From f94c6f433dba3924b79f137cfcc49d2dfd4d679c Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Thu, 16 Jun 2022 09:55:44 -0700 Subject: [PATCH] fix(router): Expose CanMatchFn as public API (#46394) The `CanMatchFn` is already exposed in the type signature for `canMatch` on the `Route`. This function type should already be exposed as public API but was missed in the initial implementation because the older guards use the `any` type instead. PR Close #46394 --- goldens/public-api/router/index.md | 3 +++ packages/router/src/index.ts | 2 +- packages/router/src/models.ts | 7 +++++++ packages/router/test/apply_redirects.spec.ts | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/goldens/public-api/router/index.md b/goldens/public-api/router/index.md index 1f5babe084e..a7d81826f25 100644 --- a/goldens/public-api/router/index.md +++ b/goldens/public-api/router/index.md @@ -141,6 +141,9 @@ export interface CanMatch { canMatch(route: Route, segments: UrlSegment[]): Observable | Promise | boolean | UrlTree; } +// @public +export type CanMatchFn = (route: Route, segments: UrlSegment[]) => Observable | Promise | boolean; + // @public export class ChildActivationEnd { constructor( diff --git a/packages/router/src/index.ts b/packages/router/src/index.ts index 3359a714e23..9a5f233526c 100644 --- a/packages/router/src/index.ts +++ b/packages/router/src/index.ts @@ -12,7 +12,7 @@ export {RouterLink, RouterLinkWithHref} from './directives/router_link'; export {RouterLinkActive} from './directives/router_link_active'; export {RouterOutlet, RouterOutletContract} from './directives/router_outlet'; export {ActivationEnd, ActivationStart, ChildActivationEnd, ChildActivationStart, Event, EventType, GuardsCheckEnd, GuardsCheckStart, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, RouterEvent, RoutesRecognized, Scroll} from './events'; -export {CanActivate, CanActivateChild, CanDeactivate, CanLoad, CanMatch, Data, LoadChildren, LoadChildrenCallback, QueryParamsHandling, Resolve, ResolveData, Route, Routes, RunGuardsAndResolvers, UrlMatcher, UrlMatchResult} from './models'; +export {CanActivate, CanActivateChild, CanDeactivate, CanLoad, CanMatch, CanMatchFn, Data, LoadChildren, LoadChildrenCallback, QueryParamsHandling, Resolve, ResolveData, Route, Routes, RunGuardsAndResolvers, UrlMatcher, UrlMatchResult} from './models'; export {DefaultTitleStrategy, TitleStrategy} from './page_title_strategy'; export {BaseRouteReuseStrategy, DetachedRouteHandle, RouteReuseStrategy} from './route_reuse_strategy'; export {Navigation, NavigationBehaviorOptions, NavigationExtras, Router, UrlCreationOptions} from './router'; diff --git a/packages/router/src/models.ts b/packages/router/src/models.ts index 8fd18c38db7..a4167a92e51 100644 --- a/packages/router/src/models.ts +++ b/packages/router/src/models.ts @@ -907,6 +907,13 @@ export interface CanMatch { Observable|Promise|boolean|UrlTree; } +/** + * The signature of a function used as a `CanMatch` guard on a `Route`. + * + * @publicApi + * @see `CanMatch` + * @see `Route` + */ export type CanMatchFn = (route: Route, segments: UrlSegment[]) => Observable|Promise|boolean; diff --git a/packages/router/test/apply_redirects.spec.ts b/packages/router/test/apply_redirects.spec.ts index 3542f2f3f87..d4c2e39bfc4 100644 --- a/packages/router/test/apply_redirects.spec.ts +++ b/packages/router/test/apply_redirects.spec.ts @@ -262,7 +262,7 @@ describe('applyRedirects', () => { throw 'Should not be reached'; } }); - }) + }); describe('lazy loading', () => { it('should load config on demand', () => {