88
99import { EnvironmentInjector , Type , ɵRuntimeError as RuntimeError } from '@angular/core' ;
1010import { from , Observable , of } from 'rxjs' ;
11- import { catchError , concatMap , defaultIfEmpty , first , last , map , mergeMap , scan , switchMap , tap } from 'rxjs/operators' ;
11+ import { catchError , concatMap , defaultIfEmpty , first , last as rxjsLast , map , mergeMap , scan , switchMap , tap } from 'rxjs/operators' ;
1212
1313import { AbsoluteRedirect , ApplyRedirects , canLoadFails , noMatch , NoMatch } from './apply_redirects' ;
1414import { createUrlTreeFromSnapshot } from './create_url_tree' ;
@@ -19,8 +19,9 @@ import {RouterConfigLoader} from './router_config_loader';
1919import { ActivatedRouteSnapshot , getInherited , ParamsInheritanceStrategy , RouterStateSnapshot } from './router_state' ;
2020import { PRIMARY_OUTLET } from './shared' ;
2121import { UrlSegment , UrlSegmentGroup , UrlSerializer , UrlTree } from './url_tree' ;
22+ import { last } from './utils/collection' ;
2223import { getOutlet , sortByMatchingOutlets } from './utils/config' ;
23- import { isImmediateMatch , match , matchWithChecks , noLeftoversInUrl , split } from './utils/config_matching' ;
24+ import { isImmediateMatch , match , MatchResult , matchWithChecks , noLeftoversInUrl , split } from './utils/config_matching' ;
2425import { TreeNode } from './utils/tree' ;
2526import { isEmptyError } from './utils/type_guards' ;
2627
@@ -161,7 +162,7 @@ export class Recognizer {
161162 return children ;
162163 } ) ,
163164 defaultIfEmpty ( null as TreeNode < ActivatedRouteSnapshot > [ ] | null ) ,
164- last ( ) ,
165+ rxjsLast ( ) ,
165166 mergeMap ( children => {
166167 if ( children === null ) return noMatch ( segmentGroup ) ;
167168 // Because we may have matched two outlets to the same empty path segment, we can have
@@ -234,7 +235,8 @@ export class Recognizer {
234235 consumedSegments,
235236 positionalParamSegments,
236237 remainingSegments,
237- } = match ( segmentGroup , route , segments ) ;
238+ } = route . path === '**' ? createWildcardMatchResult ( segments ) :
239+ match ( segmentGroup , route , segments ) ;
238240 if ( ! matched ) return noMatch ( segmentGroup ) ;
239241
240242 // TODO(atscott): Move all of this under an if(ngDevMode) as a breaking change and allow stack
@@ -266,13 +268,17 @@ export class Recognizer {
266268 matchSegmentAgainstRoute (
267269 injector : EnvironmentInjector , rawSegment : UrlSegmentGroup , route : Route ,
268270 segments : UrlSegment [ ] , outlet : string ) : Observable < TreeNode < ActivatedRouteSnapshot > > {
269- const matchResult = matchWithChecks ( rawSegment , route , segments , injector , this . urlSerializer ) ;
271+ let matchResult : Observable < MatchResult > ;
272+
270273 if ( route . path === '**' ) {
274+ matchResult = of ( createWildcardMatchResult ( segments ) ) ;
271275 // Prior versions of the route matching algorithm would stop matching at the wildcard route.
272276 // We should investigate a better strategy for any existing children. Otherwise, these
273277 // child segments are silently dropped from the navigation.
274278 // https://github.com/angular/angular/issues/40089
275279 rawSegment . children = { } ;
280+ } else {
281+ matchResult = matchWithChecks ( rawSegment , route , segments , injector , this . urlSerializer ) ;
276282 }
277283
278284 return matchResult . pipe ( switchMap ( ( result ) => {
@@ -431,3 +437,13 @@ function getData(route: Route): Data {
431437function getResolve ( route : Route ) : ResolveData {
432438 return route . resolve || { } ;
433439}
440+
441+ function createWildcardMatchResult ( segments : UrlSegment [ ] ) : MatchResult {
442+ return {
443+ matched : true ,
444+ parameters : segments . length > 0 ? last ( segments ) ! . parameters : { } ,
445+ consumedSegments : segments ,
446+ remainingSegments : [ ] ,
447+ positionalParamSegments : { } ,
448+ } ;
449+ }
0 commit comments