Skip to content

Commit b2aff43

Browse files
atscottjosephperrott
authored andcommitted
fix(router): Remove urlHandlingStrategy from public Router properties (#51631)
This commit removes the `urlHandlingStrategy` from the public Router's API BREAKING CHANGE: `urlHandlingStrategy` has been removed from the Router public API. This should instead be configured through the provideRouter or RouterModule.forRoot APIs. PR Close #51631
1 parent 3c0c53d commit b2aff43

File tree

5 files changed

+8
-29
lines changed

5 files changed

+8
-29
lines changed

aio/content/guide/deprecations.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,6 @@ The following strategies are meant to be configured by registering the
429429
application strategy in DI via the `providers` in the root `NgModule` or
430430
`bootstrapApplication`:
431431
* `routeReuseStrategy`
432-
* `urlHandlingStrategy`
433432

434433
The following options are meant to be configured using the options
435434
available in `RouterModule.forRoot` or `provideRouter` and `withRouterConfig`.

goldens/public-api/router/index.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,9 +717,6 @@ export class Router {
717717
serializeUrl(url: UrlTree): string;
718718
setUpLocationChangeListener(): void;
719719
get url(): string;
720-
// @deprecated
721-
get urlHandlingStrategy(): UrlHandlingStrategy;
722-
set urlHandlingStrategy(value: UrlHandlingStrategy);
723720
// (undocumented)
724721
static ɵfac: i0.ɵɵFactoryDeclaration<Router, never>;
725722
// (undocumented)

packages/router/src/navigation_transition.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ interface InternalRouterInterface {
274274
// available in DI.
275275
errorHandler: (error: any) => any;
276276
navigated: boolean;
277-
urlHandlingStrategy: UrlHandlingStrategy;
278277
routeReuseStrategy: RouteReuseStrategy;
279278
onSameUrlNavigation: 'reload'|'ignore';
280279
}
@@ -303,6 +302,7 @@ export class NavigationTransitions {
303302
private readonly options = inject(ROUTER_CONFIGURATION, {optional: true}) || {};
304303
private readonly paramsInheritanceStrategy =
305304
this.options.paramsInheritanceStrategy || 'emptyOnly';
305+
private readonly urlHandlingStrategy = inject(UrlHandlingStrategy);
306306

307307
navigationId = 0;
308308
get hasRequestedNavigation() {
@@ -347,8 +347,8 @@ export class NavigationTransitions {
347347
currentUrlTree: initialUrlTree,
348348
currentRawUrl: initialUrlTree,
349349
currentBrowserUrl: initialUrlTree,
350-
extractedUrl: router.urlHandlingStrategy.extract(initialUrlTree),
351-
urlAfterRedirects: router.urlHandlingStrategy.extract(initialUrlTree),
350+
extractedUrl: this.urlHandlingStrategy.extract(initialUrlTree),
351+
urlAfterRedirects: this.urlHandlingStrategy.extract(initialUrlTree),
352352
rawUrl: initialUrlTree,
353353
extras: {},
354354
resolve: null,
@@ -368,7 +368,7 @@ export class NavigationTransitions {
368368

369369
// Extract URL
370370
map(t =>
371-
({...t, extractedUrl: router.urlHandlingStrategy.extract(t.rawUrl)} as
371+
({...t, extractedUrl: this.urlHandlingStrategy.extract(t.rawUrl)} as
372372
NavigationTransition)),
373373

374374
// Using switchMap so we cancel executing navigations when a new one comes in
@@ -417,7 +417,7 @@ export class NavigationTransitions {
417417
return EMPTY;
418418
}
419419

420-
if (router.urlHandlingStrategy.shouldProcessUrl(t.rawUrl)) {
420+
if (this.urlHandlingStrategy.shouldProcessUrl(t.rawUrl)) {
421421
return of(t).pipe(
422422
// Fire NavigationStart event
423423
switchMap(t => {
@@ -458,7 +458,7 @@ export class NavigationTransitions {
458458
}));
459459
} else if (
460460
urlTransition &&
461-
router.urlHandlingStrategy.shouldProcessUrl(t.currentRawUrl)) {
461+
this.urlHandlingStrategy.shouldProcessUrl(t.currentRawUrl)) {
462462
/* When the current URL shouldn't be processed, but the previous one
463463
* was, we handle this "error condition" by navigating to the
464464
* previously successful URL, but leaving the URL intact.*/

packages/router/src/router.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export class Router {
9494
private readonly navigationTransitions = inject(NavigationTransitions);
9595
private readonly urlSerializer = inject(UrlSerializer);
9696
private readonly location = inject(Location);
97+
private readonly urlHandlingStrategy = inject(UrlHandlingStrategy);
9798

9899
/**
99100
* The private `Subject` type for the public events exposed in the getter. This is used internally
@@ -144,24 +145,6 @@ export class Router {
144145
*/
145146
navigated: boolean = false;
146147

147-
/**
148-
* A strategy for extracting and merging URLs.
149-
* Used for AngularJS to Angular migrations.
150-
*
151-
* @deprecated Configure using `providers` instead:
152-
* `{provide: UrlHandlingStrategy, useClass: MyStrategy}`.
153-
*/
154-
get urlHandlingStrategy(): UrlHandlingStrategy {
155-
return this.stateManager.urlHandlingStrategy;
156-
}
157-
/**
158-
* @deprecated Configure using `providers` instead:
159-
* `{provide: UrlHandlingStrategy, useClass: MyStrategy}`.
160-
*/
161-
set urlHandlingStrategy(value: UrlHandlingStrategy) {
162-
this.stateManager.urlHandlingStrategy = value;
163-
}
164-
165148
/**
166149
* A strategy for re-using routes.
167150
*

packages/router/test/integration.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ describe('Integration', () => {
975975
expect((router as any).browserUrlTree.toString()).toBe('/team/22');
976976

977977
// Force to not process URL changes
978-
router.urlHandlingStrategy.shouldProcessUrl = (url: UrlTree) => false;
978+
TestBed.inject(UrlHandlingStrategy).shouldProcessUrl = (url: UrlTree) => false;
979979

980980
router.navigateByUrl('/login');
981981
advance(fixture, 1);

0 commit comments

Comments
 (0)