Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0aa0e9a

Browse filesBrowse files
committed
fixup! fix(router): eagerly update internal state on browser-triggered navigations
1 parent ff32c85 commit 0aa0e9a
Copy full SHA for 0aa0e9a

File tree

Expand file treeCollapse file tree

2 files changed

+12
-5
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-5
lines changed

‎packages/core/test/bundling/router/bundle.golden_symbols.json

Copy file name to clipboardExpand all lines: packages/core/test/bundling/router/bundle.golden_symbols.json
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,9 @@
15261526
{
15271527
"name": "isArrayLike"
15281528
},
1529+
{
1530+
"name": "isBrowserTriggeredNavigation"
1531+
},
15291532
{
15301533
"name": "isCommandWithOutlets"
15311534
},

‎packages/router/src/router.ts

Copy file name to clipboardExpand all lines: packages/router/src/router.ts
+9-5Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ export class Router {
638638

639639
// If the source of the navigation is from a browser event, the URL is
640640
// already updated. We already need to sync the internal state.
641-
if (t.source !== 'imperative') {
641+
if (isBrowserTriggeredNavigation(t.source)) {
642642
this.browserUrlTree = t.rawUrl;
643643
}
644644

@@ -964,8 +964,8 @@ export class Router {
964964
// updates or if the navigation was triggered by the browser (back
965965
// button, URL bar, etc). We want to replace that item in history if
966966
// the navigation is rejected.
967-
replaceUrl:
968-
this.urlUpdateStrategy === 'eager' || t.source !== 'imperative'
967+
replaceUrl: this.urlUpdateStrategy === 'eager' ||
968+
isBrowserTriggeredNavigation(t.source)
969969
};
970970

971971
this.scheduleNavigation(
@@ -1396,8 +1396,8 @@ export class Router {
13961396
const lastNavigation = this.getTransition();
13971397
// We don't want to skip duplicate successful navs if they're imperative because
13981398
// onSameUrlNavigation could be 'reload' (so the duplicate is intended).
1399-
const browserNavPrecededByRouterNav =
1400-
source !== 'imperative' && lastNavigation?.source === 'imperative';
1399+
const browserNavPrecededByRouterNav = isBrowserTriggeredNavigation(source) && lastNavigation &&
1400+
!isBrowserTriggeredNavigation(lastNavigation.source);
14011401
const lastNavigationSucceeded = this.lastSuccessfulId === lastNavigation.id;
14021402
// If the last navigation succeeded or is in flight, we can use the rawUrl as the comparison.
14031403
// However, if it failed, we should compare to the final result (urlAfterRedirects).
@@ -1560,3 +1560,7 @@ function validateCommands(commands: string[]): void {
15601560
}
15611561
}
15621562
}
1563+
1564+
function isBrowserTriggeredNavigation(source: 'imperative'|'popstate'|'hashchange') {
1565+
return source !== 'imperative';
1566+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.