Skip to content

Commit

Permalink
fix(router): Remove deprecated Router properties (#51502)
Browse files Browse the repository at this point in the history
This commit removes deprecated properties on the Router. These are meant
to be configured through DI and not meant to be changed during runtime.

BREAKING CHANGE: The following Router properties have been removed from
the public API:

- canceledNavigationResolution
- paramsInheritanceStrategy
- titleStrategy
- urlUpdateStrategy
- malformedUriErrorHandler

These should instead be configured through the `provideRouter` or
`RouterModule.forRoot` APIs.

PR Close #51502
  • Loading branch information
atscott authored and jessicajaniuk committed Aug 29, 2023
1 parent 0b6aae8 commit c62e680
Show file tree
Hide file tree
Showing 7 changed files with 585 additions and 675 deletions.
4 changes: 0 additions & 4 deletions aio/content/guide/deprecations.md
Expand Up @@ -429,15 +429,11 @@ 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`
* `titleStrategy`
* `urlHandlingStrategy`

The following options are meant to be configured using the options
available in `RouterModule.forRoot` or `provideRouter` and `withRouterConfig`.
* `onSameUrlNavigation`
* `paramsInheritanceStrategy`
* `urlUpdateStrategy`
* `canceledNavigationResolution`
* `errorHandler`

The following options are deprecated in entirely:
Expand Down
10 changes: 0 additions & 10 deletions goldens/public-api/router/index.md
Expand Up @@ -687,8 +687,6 @@ export class RouteConfigLoadStart {
// @public
export class Router {
constructor();
// @deprecated
canceledNavigationResolution: 'replace' | 'computed';
readonly componentInputBindingEnabled: boolean;
// (undocumented)
config: Routes;
Expand All @@ -703,31 +701,23 @@ export class Router {
isActive(url: string | UrlTree, exact: boolean): boolean;
isActive(url: string | UrlTree, matchOptions: IsActiveMatchOptions): boolean;
get lastSuccessfulNavigation(): Navigation | null;
// @deprecated
malformedUriErrorHandler: (error: URIError, urlSerializer: UrlSerializer, url: string) => UrlTree;
navigate(commands: any[], extras?: NavigationExtras): Promise<boolean>;
navigateByUrl(url: string | UrlTree, extras?: NavigationBehaviorOptions): Promise<boolean>;
navigated: boolean;
// (undocumented)
ngOnDestroy(): void;
// @deprecated
onSameUrlNavigation: OnSameUrlNavigation;
// @deprecated
paramsInheritanceStrategy: 'emptyOnly' | 'always';
parseUrl(url: string): UrlTree;
resetConfig(config: Routes): void;
// @deprecated
routeReuseStrategy: RouteReuseStrategy;
readonly routerState: RouterState;
serializeUrl(url: UrlTree): string;
setUpLocationChangeListener(): void;
// @deprecated
titleStrategy?: TitleStrategy;
get url(): string;
// @deprecated
urlHandlingStrategy: UrlHandlingStrategy;
// @deprecated
urlUpdateStrategy: 'deferred' | 'eager';
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<Router, never>;
// (undocumented)
Expand Down
15 changes: 9 additions & 6 deletions packages/router/src/navigation_transition.ts
Expand Up @@ -22,7 +22,7 @@ import {resolveData} from './operators/resolve_data';
import {switchTap} from './operators/switch_tap';
import {TitleStrategy} from './page_title_strategy';
import {RouteReuseStrategy} from './route_reuse_strategy';
import {ErrorHandler} from './router_config';
import {ErrorHandler, ROUTER_CONFIGURATION} from './router_config';
import {RouterConfigLoader} from './router_config_loader';
import {ChildrenOutletContexts} from './router_outlet_context';
import {ActivatedRoute, ActivatedRouteSnapshot, createEmptyState, RouterState, RouterStateSnapshot} from './router_state';
Expand Down Expand Up @@ -267,12 +267,10 @@ interface InternalRouterInterface {
// writeable. Ideally, these would be removed and the values retrieved instead from the values
// available in DI.
errorHandler: ErrorHandler;
titleStrategy?: TitleStrategy;
navigated: boolean;
urlHandlingStrategy: UrlHandlingStrategy;
routeReuseStrategy: RouteReuseStrategy;
onSameUrlNavigation: 'reload'|'ignore';
paramsInheritanceStrategy: 'emptyOnly'|'always';
}

@Injectable({providedIn: 'root'})
Expand All @@ -295,6 +293,11 @@ export class NavigationTransitions {
private readonly urlSerializer = inject(UrlSerializer);
private readonly rootContexts = inject(ChildrenOutletContexts);
private readonly inputBindingEnabled = inject(INPUT_BINDER, {optional: true}) !== null;
private readonly titleStrategy?: TitleStrategy = inject(TitleStrategy);
private readonly options = inject(ROUTER_CONFIGURATION, {optional: true}) || {};
private readonly paramsInheritanceStrategy =
this.options.paramsInheritanceStrategy || 'emptyOnly';

navigationId = 0;
get hasRequestedNavigation() {
return this.navigationId !== 0;
Expand Down Expand Up @@ -429,7 +432,7 @@ export class NavigationTransitions {
recognize(
this.environmentInjector, this.configLoader,
this.rootComponentType, router.config, this.urlSerializer,
router.paramsInheritanceStrategy),
this.paramsInheritanceStrategy),

// Update URL if in `eager` update mode
tap(t => {
Expand Down Expand Up @@ -545,7 +548,7 @@ export class NavigationTransitions {
let dataResolved = false;
return of(t).pipe(
resolveData(
router.paramsInheritanceStrategy,
this.paramsInheritanceStrategy,
this.environmentInjector),
tap({
next: () => dataResolved = true,
Expand Down Expand Up @@ -627,7 +630,7 @@ export class NavigationTransitions {
this.events.next(new NavigationEnd(
t.id, this.urlSerializer.serialize(t.extractedUrl),
this.urlSerializer.serialize(t.urlAfterRedirects!)));
router.titleStrategy?.updateTitle(t.targetRouterState!.snapshot);
this.titleStrategy?.updateTitle(t.targetRouterState!.snapshot);
t.resolve(true);
},
complete: () => {
Expand Down
47 changes: 3 additions & 44 deletions packages/router/src/router.ts
Expand Up @@ -16,7 +16,6 @@ import {RuntimeErrorCode} from './errors';
import {BeforeActivateRoutes, Event, IMPERATIVE_NAVIGATION, NavigationCancel, NavigationCancellationCode, NavigationEnd, NavigationError, NavigationSkipped, NavigationStart, NavigationTrigger, PrivateRouterEvents, RedirectRequest, RoutesRecognized} from './events';
import {NavigationBehaviorOptions, OnSameUrlNavigation, Routes} from './models';
import {isBrowserTriggeredNavigation, Navigation, NavigationExtras, NavigationTransition, NavigationTransitions, RestoredState, UrlCreationOptions} from './navigation_transition';
import {TitleStrategy} from './page_title_strategy';
import {RouteReuseStrategy} from './route_reuse_strategy';
import {ROUTER_CONFIGURATION} from './router_config';
import {ROUTES} from './router_config_loader';
Expand Down Expand Up @@ -201,11 +200,9 @@ export class Router {
* The most common case is a `%` sign
* that's not encoded and is not part of a percent encoded sequence.
*
* @deprecated URI parsing errors should be handled in the `UrlSerializer`.
*
* @see {@link RouterModule}
*/
malformedUriErrorHandler =
private malformedUriErrorHandler =
this.options.malformedUriErrorHandler || defaultMalformedUriErrorHandler;

/**
Expand All @@ -232,14 +229,6 @@ export class Router {
*/
routeReuseStrategy = inject(RouteReuseStrategy);

/**
* A strategy for setting the title based on the `routerState`.
*
* @deprecated Configure using `providers` instead:
* `{provide: TitleStrategy, useClass: MyStrategy}`.
*/
titleStrategy?: TitleStrategy = inject(TitleStrategy);

/**
* How to handle a navigation request to the current URL.
*
Expand All @@ -251,36 +240,7 @@ export class Router {
*/
onSameUrlNavigation: OnSameUrlNavigation = this.options.onSameUrlNavigation || 'ignore';

/**
* How to merge parameters, data, resolved data, and title from parent to child
* routes. One of:
*
* - `'emptyOnly'` : Inherit parent parameters, data, and resolved data
* for path-less or component-less routes.
* - `'always'` : Inherit parent parameters, data, and resolved data
* for all child routes.
*
* @deprecated Configure this through `provideRouter` or `RouterModule.forRoot` instead.
* @see {@link withRouterConfig}
* @see {@link provideRouter}
* @see {@link RouterModule}
*/
paramsInheritanceStrategy: 'emptyOnly'|'always' =
this.options.paramsInheritanceStrategy || 'emptyOnly';

/**
* Determines when the router updates the browser URL.
* By default (`"deferred"`), updates the browser URL after navigation has finished.
* Set to `'eager'` to update the browser URL at the beginning of navigation.
* You can choose to update early so that, if navigation fails,
* you can show an error message with the URL that failed.
*
* @deprecated Configure this through `provideRouter` or `RouterModule.forRoot` instead.
* @see {@link withRouterConfig}
* @see {@link provideRouter}
* @see {@link RouterModule}
*/
urlUpdateStrategy: 'deferred'|'eager' = this.options.urlUpdateStrategy || 'deferred';
private urlUpdateStrategy: 'deferred'|'eager' = this.options.urlUpdateStrategy || 'deferred';

/**
* Configures how the Router attempts to restore state when a navigation is cancelled.
Expand All @@ -303,12 +263,11 @@ export class Router {
*
* The default value is `replace`.
*
* @deprecated Configure this through `provideRouter` or `RouterModule.forRoot` instead.
* @see {@link withRouterConfig}
* @see {@link provideRouter}
* @see {@link RouterModule}
*/
canceledNavigationResolution: 'replace'|'computed' =
private canceledNavigationResolution: 'replace'|'computed' =
this.options.canceledNavigationResolution || 'replace';

config: Routes = inject(ROUTES, {optional: true})?.flat() ?? [];
Expand Down

0 comments on commit c62e680

Please sign in to comment.