Skip to content

Commit 15eccef

Browse files
atscottalxhub
authored andcommitted
docs(router): Clean up error handler deprecations (#48551)
`errorHandler` and `malformedUriErrorHandler` were already deprecated in the Router class public API. This change updates the deprecation to extend to `RouterModule.forRoot` configuration options. PR Close #48551
1 parent 31b94c7 commit 15eccef

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

aio/content/guide/deprecations.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,9 @@ available in `RouterModule.forRoot` or `provideRouter` and `withRouterConfig`.
398398
* `canceledNavigationResolution`
399399
* `errorHandler`
400400

401-
The following options are available in `RouterModule.forRoot` but not
402-
available in `provideRouter`:
403-
* `malformedUriErrorHandler` - This was not found to be used by anyone.
404-
There are currently no plans to make this available in `provideRouter`.
401+
The following options are deprecated in entirely:
402+
* `malformedUriErrorHandler` - URI parsing errors should be handled in the `UrlSerializer` instead.
403+
* `errorHandler` - Subscribe to the `Router` events and filter for `NavigationError` instead.
405404

406405
<a id="router-can-load"></a>
407406

goldens/public-api/router/index.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,6 @@ export type DisabledInitialNavigationFeature = RouterFeature<RouterFeatureKind.D
246246
// @public
247247
export type EnabledBlockingInitialNavigationFeature = RouterFeature<RouterFeatureKind.EnabledBlockingInitialNavigationFeature>;
248248

249-
// @public
250-
export type ErrorHandlerFeature = RouterFeature<RouterFeatureKind.NavigationErrorHandlerFeature>;
251-
252249
// @public
253250
type Event_2 = RouterEvent | NavigationStart | NavigationEnd | NavigationCancel | NavigationError | RoutesRecognized | GuardsCheckStart | GuardsCheckEnd | RouteConfigLoadStart | RouteConfigLoadEnd | ChildActivationStart | ChildActivationEnd | ActivationStart | ActivationEnd | Scroll | ResolveStart | ResolveEnd | NavigationSkipped;
254251
export { Event_2 as Event }
@@ -294,8 +291,10 @@ export const enum EventType {
294291
// @public
295292
export interface ExtraOptions extends InMemoryScrollingOptions, RouterConfigOptions {
296293
enableTracing?: boolean;
297-
errorHandler?: ErrorHandler;
294+
// @deprecated
295+
errorHandler?: (error: any) => any;
298296
initialNavigation?: InitialNavigation;
297+
// @deprecated
299298
malformedUriErrorHandler?: (error: URIError, urlSerializer: UrlSerializer, url: string) => UrlTree;
300299
preloadingStrategy?: any;
301300
scrollOffset?: [number, number] | (() => [number, number]);
@@ -442,6 +441,9 @@ export class NavigationError extends RouterEvent {
442441
readonly type = EventType.NavigationError;
443442
}
444443

444+
// @public
445+
export type NavigationErrorHandlerFeature = RouterFeature<RouterFeatureKind.NavigationErrorHandlerFeature>;
446+
445447
// @public
446448
export interface NavigationExtras extends UrlCreationOptions, NavigationBehaviorOptions {
447449
}
@@ -665,7 +667,7 @@ export class Router {
665667
createUrlTree(commands: any[], navigationExtras?: UrlCreationOptions): UrlTree;
666668
dispose(): void;
667669
// @deprecated
668-
errorHandler: ErrorHandler;
670+
errorHandler: (error: any) => any;
669671
get events(): Observable<Event_2>;
670672
getCurrentNavigation(): Navigation | null;
671673
initialNavigation(): void;
@@ -751,7 +753,7 @@ export interface RouterFeature<FeatureKind extends RouterFeatureKind> {
751753
}
752754

753755
// @public
754-
export type RouterFeatures = PreloadingFeature | DebugTracingFeature | InitialNavigationFeature | InMemoryScrollingFeature | RouterConfigurationFeature | ErrorHandlerFeature;
756+
export type RouterFeatures = PreloadingFeature | DebugTracingFeature | InitialNavigationFeature | InMemoryScrollingFeature | RouterConfigurationFeature | NavigationErrorHandlerFeature;
755757

756758
// @public
757759
export type RouterHashLocationFeature = RouterFeature<RouterFeatureKind.RouterHashLocationFeature>;
@@ -1074,15 +1076,15 @@ export function withDisabledInitialNavigation(): DisabledInitialNavigationFeatur
10741076
// @public
10751077
export function withEnabledBlockingInitialNavigation(): EnabledBlockingInitialNavigationFeature;
10761078

1077-
// @public
1078-
export function withErrorHandler(fn: (error: NavigationError) => void): ErrorHandlerFeature;
1079-
10801079
// @public
10811080
export function withHashLocation(): RouterConfigurationFeature;
10821081

10831082
// @public
10841083
export function withInMemoryScrolling(options?: InMemoryScrollingOptions): InMemoryScrollingFeature;
10851084

1085+
// @public
1086+
export function withNavigationErrorHandler(fn: (error: NavigationError) => void): NavigationErrorHandlerFeature;
1087+
10861088
// @public
10871089
export function withPreloading(preloadingStrategy: Type<PreloadingStrategy>): PreloadingFeature;
10881090

packages/router/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export {ActivationEnd, ActivationStart, ChildActivationEnd, ChildActivationStart
1515
export {CanActivate, CanActivateChild, CanActivateChildFn, CanActivateFn, CanDeactivate, CanDeactivateFn, CanLoad, CanLoadFn, CanMatch, CanMatchFn, Data, DefaultExport, LoadChildren, LoadChildrenCallback, NavigationBehaviorOptions, OnSameUrlNavigation, QueryParamsHandling, Resolve, ResolveData, ResolveFn, Route, Routes, RunGuardsAndResolvers, UrlMatcher, UrlMatchResult} from './models';
1616
export {Navigation, NavigationExtras, UrlCreationOptions} from './navigation_transition';
1717
export {DefaultTitleStrategy, TitleStrategy} from './page_title_strategy';
18-
export {DebugTracingFeature, DisabledInitialNavigationFeature, EnabledBlockingInitialNavigationFeature, InitialNavigationFeature, InMemoryScrollingFeature, NavigationErrorHandlerFeature as ErrorHandlerFeature, PreloadingFeature, provideRouter, provideRoutes, RouterConfigurationFeature, RouterFeature, RouterFeatures, RouterHashLocationFeature, withDebugTracing, withDisabledInitialNavigation, withEnabledBlockingInitialNavigation, withHashLocation, withInMemoryScrolling, withNavigationErrorHandler as withErrorHandler, withPreloading, withRouterConfig} from './provide_router';
18+
export {DebugTracingFeature, DisabledInitialNavigationFeature, EnabledBlockingInitialNavigationFeature, InitialNavigationFeature, InMemoryScrollingFeature, NavigationErrorHandlerFeature, PreloadingFeature, provideRouter, provideRoutes, RouterConfigurationFeature, RouterFeature, RouterFeatures, RouterHashLocationFeature, withDebugTracing, withDisabledInitialNavigation, withEnabledBlockingInitialNavigation, withHashLocation, withInMemoryScrolling, withNavigationErrorHandler, withPreloading, withRouterConfig} from './provide_router';
1919
export {BaseRouteReuseStrategy, DetachedRouteHandle, RouteReuseStrategy} from './route_reuse_strategy';
2020
export {Router} from './router';
2121
export {ExtraOptions, InitialNavigation, InMemoryScrollingOptions, ROUTER_CONFIGURATION, RouterConfigOptions} from './router_config';

packages/router/src/router.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88

99
import {Location} from '@angular/common';
10-
import {Compiler, inject, Injectable, Injector, NgZone, Type, ɵConsole as Console, ɵRuntimeError as RuntimeError} from '@angular/core';
11-
import {BehaviorSubject, Observable, of, SubscriptionLike} from 'rxjs';
10+
import {inject, Injectable, NgZone, Type, ɵConsole as Console, ɵRuntimeError as RuntimeError} from '@angular/core';
11+
import {Observable, of, SubscriptionLike} from 'rxjs';
1212

1313
import {CreateUrlTreeStrategy} from './create_url_tree_strategy';
1414
import {RuntimeErrorCode} from './errors';
@@ -17,9 +17,8 @@ import {NavigationBehaviorOptions, OnSameUrlNavigation, Routes} from './models';
1717
import {Navigation, NavigationExtras, NavigationTransition, NavigationTransitions, RestoredState, UrlCreationOptions} from './navigation_transition';
1818
import {TitleStrategy} from './page_title_strategy';
1919
import {RouteReuseStrategy} from './route_reuse_strategy';
20-
import {ErrorHandler, ExtraOptions, ROUTER_CONFIGURATION} from './router_config';
20+
import {ROUTER_CONFIGURATION} from './router_config';
2121
import {ROUTES} from './router_config_loader';
22-
import {ChildrenOutletContexts} from './router_outlet_context';
2322
import {createEmptyState, RouterState} from './router_state';
2423
import {Params} from './shared';
2524
import {UrlHandlingStrategy} from './url_handling_strategy';
@@ -180,6 +179,8 @@ export class Router {
180179
* A handler for navigation errors in this NgModule.
181180
*
182181
* @deprecated Subscribe to the `Router` events and watch for `NavigationError` instead.
182+
* `provideRouter` has the `withErrorHandler` feature to make this easier.
183+
* @see `withErrorHandler`
183184
*/
184185
errorHandler = this.options.errorHandler || defaultErrorHandler;
185186

@@ -189,8 +190,8 @@ export class Router {
189190
* The most common case is a `%` sign
190191
* that's not encoded and is not part of a percent encoded sequence.
191192
*
192-
* @deprecated Configure this through `RouterModule.forRoot` instead:
193-
* `RouterModule.forRoot(routes, {malformedUriErrorHandler: myHandler})`
193+
* @deprecated URI parsing errors should be handled in the `UrlSerializer`.
194+
*
194195
* @see `RouterModule`
195196
*/
196197
malformedUriErrorHandler =

packages/router/src/router_config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const NG_DEV_MODE = typeof ngDevMode === 'undefined' || !!ngDevMode;
2121
* the exception.
2222
*
2323
* @publicApi
24+
* @deprecated Subscribe to the `Router` events and watch for `NavigationError` instead.
2425
*/
2526
export type ErrorHandler = (error: any) => any;
2627

@@ -202,8 +203,9 @@ export interface ExtraOptions extends InMemoryScrollingOptions, RouterConfigOpti
202203
* If the handler returns a value, the navigation Promise is resolved with this value.
203204
* If the handler throws an exception, the navigation Promise is rejected with the exception.
204205
*
206+
* @deprecated Subscribe to the `Router` events and watch for `NavigationError` instead.
205207
*/
206-
errorHandler?: ErrorHandler;
208+
errorHandler?: (error: any) => any;
207209

208210
/**
209211
* Configures a preloading strategy.
@@ -230,6 +232,8 @@ export interface ExtraOptions extends InMemoryScrollingOptions, RouterConfigOpti
230232
* - `'URIError'` - Error thrown when parsing a bad URL.
231233
* - `'UrlSerializer'` - UrlSerializer that’s configured with the router.
232234
* - `'url'` - The malformed URL that caused the URIError
235+
*
236+
* @deprecated URI parsing errors should be handled in the `UrlSerializer` instead.
233237
* */
234238
malformedUriErrorHandler?:
235239
(error: URIError, urlSerializer: UrlSerializer, url: string) => UrlTree;

0 commit comments

Comments
 (0)