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 772e08d

Browse filesBrowse files
atscottAndrewKushnir
authored andcommitted
fix(router): fix Router's public API for canceledNavigationResolution (#43842)
The commit which made the `canceledNavigationResolution` property on the `Router` public did not add the corresponding configuration in the `ExtraOptions`. 3c6b653 This was a mistake and is being corrected in this commit. We should not encourage changing the properties post-setup (i.e. `inject(Router).canceledNavigationResolution = 'computed'`). This manner of configuration makes the options non-tree shakeable because we have to keep both implementations in case the value changes at runtime. PR Close #43842
1 parent 12dfc0e commit 772e08d
Copy full SHA for 772e08d

File tree

Expand file treeCollapse file tree

3 files changed

+31
-2
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+31
-2
lines changed

‎goldens/public-api/router/router.md

Copy file name to clipboardExpand all lines: goldens/public-api/router/router.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ export { Event_2 as Event }
184184
// @public
185185
export interface ExtraOptions {
186186
anchorScrolling?: 'disabled' | 'enabled';
187+
canceledNavigationResolution?: 'replace' | 'computed';
187188
enableTracing?: boolean;
188189
errorHandler?: ErrorHandler;
189190
initialNavigation?: InitialNavigation;

‎packages/router/src/router_module.ts

Copy file name to clipboardExpand all lines: packages/router/src/router_module.ts
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,29 @@ export interface ExtraOptions {
426426
* The default in v11 is `corrected`.
427427
*/
428428
relativeLinkResolution?: 'legacy'|'corrected';
429+
430+
/**
431+
* Configures how the Router attempts to restore state when a navigation is cancelled.
432+
*
433+
* 'replace' - Always uses `location.replaceState` to set the browser state to the state of the
434+
* router before the navigation started. This means that if the URL of the browser is updated
435+
* _before_ the navigation is canceled, the Router will simply replace the item in history rather
436+
* than trying to restore to the previous location in the session history. This happens most
437+
* frequently with `urlUpdateStrategy: 'eager'` and navigations with the browser back/forward
438+
* buttons.
439+
*
440+
* 'computed' - Will attempt to return to the same index in the session history that corresponds
441+
* to the Angular route when the navigation gets cancelled. For example, if the browser back
442+
* button is clicked and the navigation is cancelled, the Router will trigger a forward navigation
443+
* and vice versa.
444+
*
445+
* Note: the 'computed' option is incompatible with any `UrlHandlingStrategy` which only
446+
* handles a portion of the URL because the history restoration navigates to the previous place in
447+
* the browser history rather than simply resetting a portion of the URL.
448+
*
449+
* The default value is `replace` when not set.
450+
*/
451+
canceledNavigationResolution?: 'replace'|'computed';
429452
}
430453

431454
export function setupRouter(
@@ -483,6 +506,10 @@ export function assignExtraOptionsToRouter(opts: ExtraOptions, router: Router):
483506
if (opts.urlUpdateStrategy) {
484507
router.urlUpdateStrategy = opts.urlUpdateStrategy;
485508
}
509+
510+
if (opts.canceledNavigationResolution) {
511+
router.canceledNavigationResolution = opts.canceledNavigationResolution;
512+
}
486513
}
487514

488515
export function rootRoute(router: Router): ActivatedRoute {

‎packages/router/test/computed_state_restoration.spec.ts

Copy file name to clipboardExpand all lines: packages/router/test/computed_state_restoration.spec.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ describe('`restoredState#ɵrouterPageId`', () => {
8181
]
8282
});
8383
const router = TestBed.inject(Router);
84-
(router as any).canceledNavigationResolution = 'computed';
8584
const location = TestBed.inject(Location);
8685
fixture = createRoot(router, RootCmp);
8786
router.resetConfig([
@@ -486,7 +485,9 @@ function advance(fixture: ComponentFixture<any>, millis?: number): void {
486485
}
487486

488487
@NgModule({
489-
imports: [RouterTestingModule, CommonModule],
488+
imports: [
489+
RouterTestingModule.withRoutes([], {canceledNavigationResolution: 'computed'}), CommonModule
490+
],
490491
exports: [SimpleCmp, RootCmp, ThrowingCmp],
491492
entryComponents: [SimpleCmp, RootCmp, ThrowingCmp],
492493
declarations: [SimpleCmp, RootCmp, ThrowingCmp]

0 commit comments

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