Skip to content

Commit 8600732

Browse files
atscottAndrewKushnir
authored andcommitted
feat(router): Expose the default matcher for Routes used by the Router (#46913)
This commit adds the `defaultUrlMatcher` from the Router to the public API. `UrlMatcher` and `UrlMatchResult` are already in the public api so the signature of the function as well as the return value are already exposed. Any change to those or the implementation of `defaultUrlMatcher` would already be breaking so there's no additional risk in exposing the default matcher. This function can be useful for developers who want to create a custom matcher which builds on the default matcher of the Router. Currently, the only way to do this would be to copy-paste the implementation. fixes #35928 PR Close #46913
1 parent 55febc1 commit 8600732

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

goldens/public-api/router/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ export class DefaultTitleStrategy extends TitleStrategy {
210210
static ɵprov: i0.ɵɵInjectableDeclaration<DefaultTitleStrategy>;
211211
}
212212

213+
// @public
214+
export function defaultUrlMatcher(segments: UrlSegment[], segmentGroup: UrlSegmentGroup, route: Route): UrlMatchResult | null;
215+
213216
// @public
214217
export class DefaultUrlSerializer implements UrlSerializer {
215218
parse(url: string): UrlTree;

packages/router/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export {provideRoutes, ROUTER_INITIALIZER, RouterModule} from './router_module';
2222
export {ChildrenOutletContexts, OutletContext} from './router_outlet_context';
2323
export {NoPreloading, PreloadAllModules, PreloadingStrategy, RouterPreloader} from './router_preloader';
2424
export {ActivatedRoute, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot} from './router_state';
25-
export {convertToParamMap, ParamMap, Params, PRIMARY_OUTLET} from './shared';
25+
export {convertToParamMap, defaultUrlMatcher, ParamMap, Params, PRIMARY_OUTLET} from './shared';
2626
export {UrlHandlingStrategy} from './url_handling_strategy';
2727
export {DefaultUrlSerializer, IsActiveMatchOptions, UrlSegment, UrlSegmentGroup, UrlSerializer, UrlTree} from './url_tree';
2828
export {VERSION} from './version';

packages/router/src/shared.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,21 @@ export function convertToParamMap(params: Params): ParamMap {
118118
return new ParamsAsMap(params);
119119
}
120120

121-
// Matches the route configuration (`route`) against the actual URL (`segments`).
121+
/**
122+
* Matches the route configuration (`route`) against the actual URL (`segments`).
123+
*
124+
* When no matcher is defined on a `Route`, this is the matcher used by the Router by default.
125+
*
126+
* @param segments The remaining unmatched segments in the current navigation
127+
* @param segmentGroup The current segment group being matched
128+
* @param route The `Route` to match against.
129+
*
130+
* @see UrlMatchResult
131+
* @see Route
132+
*
133+
* @returns The resulting match information or `null` if the `route` should not match.
134+
* @publicApi
135+
*/
122136
export function defaultUrlMatcher(
123137
segments: UrlSegment[], segmentGroup: UrlSegmentGroup, route: Route): UrlMatchResult|null {
124138
const parts = route.path!.split('/');

0 commit comments

Comments
 (0)