Skip to content

Commit

Permalink
fix(router): Remove urlHandlingStrategy from public Router properti…
Browse files Browse the repository at this point in the history
…es (#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
  • Loading branch information
atscott authored and josephperrott committed Sep 5, 2023
1 parent 3c0c53d commit b2aff43
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 29 deletions.
1 change: 0 additions & 1 deletion aio/content/guide/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@ The following strategies are meant to be configured by registering the
application strategy in DI via the `providers` in the root `NgModule` or
`bootstrapApplication`:
* `routeReuseStrategy`
* `urlHandlingStrategy`

The following options are meant to be configured using the options
available in `RouterModule.forRoot` or `provideRouter` and `withRouterConfig`.
Expand Down
3 changes: 0 additions & 3 deletions goldens/public-api/router/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -717,9 +717,6 @@ export class Router {
serializeUrl(url: UrlTree): string;
setUpLocationChangeListener(): void;
get url(): string;
// @deprecated
get urlHandlingStrategy(): UrlHandlingStrategy;
set urlHandlingStrategy(value: UrlHandlingStrategy);
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<Router, never>;
// (undocumented)
Expand Down
12 changes: 6 additions & 6 deletions packages/router/src/navigation_transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ interface InternalRouterInterface {
// available in DI.
errorHandler: (error: any) => any;
navigated: boolean;
urlHandlingStrategy: UrlHandlingStrategy;
routeReuseStrategy: RouteReuseStrategy;
onSameUrlNavigation: 'reload'|'ignore';
}
Expand Down Expand Up @@ -303,6 +302,7 @@ export class NavigationTransitions {
private readonly options = inject(ROUTER_CONFIGURATION, {optional: true}) || {};
private readonly paramsInheritanceStrategy =
this.options.paramsInheritanceStrategy || 'emptyOnly';
private readonly urlHandlingStrategy = inject(UrlHandlingStrategy);

navigationId = 0;
get hasRequestedNavigation() {
Expand Down Expand Up @@ -347,8 +347,8 @@ export class NavigationTransitions {
currentUrlTree: initialUrlTree,
currentRawUrl: initialUrlTree,
currentBrowserUrl: initialUrlTree,
extractedUrl: router.urlHandlingStrategy.extract(initialUrlTree),
urlAfterRedirects: router.urlHandlingStrategy.extract(initialUrlTree),
extractedUrl: this.urlHandlingStrategy.extract(initialUrlTree),
urlAfterRedirects: this.urlHandlingStrategy.extract(initialUrlTree),
rawUrl: initialUrlTree,
extras: {},
resolve: null,
Expand All @@ -368,7 +368,7 @@ export class NavigationTransitions {

// Extract URL
map(t =>
({...t, extractedUrl: router.urlHandlingStrategy.extract(t.rawUrl)} as
({...t, extractedUrl: this.urlHandlingStrategy.extract(t.rawUrl)} as
NavigationTransition)),

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

if (router.urlHandlingStrategy.shouldProcessUrl(t.rawUrl)) {
if (this.urlHandlingStrategy.shouldProcessUrl(t.rawUrl)) {
return of(t).pipe(
// Fire NavigationStart event
switchMap(t => {
Expand Down Expand Up @@ -458,7 +458,7 @@ export class NavigationTransitions {
}));
} else if (
urlTransition &&
router.urlHandlingStrategy.shouldProcessUrl(t.currentRawUrl)) {
this.urlHandlingStrategy.shouldProcessUrl(t.currentRawUrl)) {
/* When the current URL shouldn't be processed, but the previous one
* was, we handle this "error condition" by navigating to the
* previously successful URL, but leaving the URL intact.*/
Expand Down
19 changes: 1 addition & 18 deletions packages/router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export class Router {
private readonly navigationTransitions = inject(NavigationTransitions);
private readonly urlSerializer = inject(UrlSerializer);
private readonly location = inject(Location);
private readonly urlHandlingStrategy = inject(UrlHandlingStrategy);

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

/**
* A strategy for extracting and merging URLs.
* Used for AngularJS to Angular migrations.
*
* @deprecated Configure using `providers` instead:
* `{provide: UrlHandlingStrategy, useClass: MyStrategy}`.
*/
get urlHandlingStrategy(): UrlHandlingStrategy {
return this.stateManager.urlHandlingStrategy;
}
/**
* @deprecated Configure using `providers` instead:
* `{provide: UrlHandlingStrategy, useClass: MyStrategy}`.
*/
set urlHandlingStrategy(value: UrlHandlingStrategy) {
this.stateManager.urlHandlingStrategy = value;
}

/**
* A strategy for re-using routes.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/router/test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ describe('Integration', () => {
expect((router as any).browserUrlTree.toString()).toBe('/team/22');

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

router.navigateByUrl('/login');
advance(fixture, 1);
Expand Down

0 comments on commit b2aff43

Please sign in to comment.