-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Closed
Labels
P4A relatively minor issue that is not relevant to core functionsA relatively minor issue that is not relevant to core functionsarea: router
Milestone
Description
Which @angular/* package(s) are relevant/related to the feature request?
router
Description
I would expect that wildcard '**' routes would run the canMatch guard.
const routes: Routes = [
{ path: 'path', component: Page1, canMatch: [() => true] },
{
path: '**',
component: Page2,
canMatch: [(route: Route, segments: UrlSegment[]) => segments.toString() === 'page2']
},
{
path: '**',
component: Page3,
canMatch: [(route: Route, segments: UrlSegment[]) => segments.toString() === 'page3']
},
];
Stackblitz sample: https://stackblitz.com/edit/angular-azxep5?file=src%2Fmain.ts
Proposed solution
Wildcard '**' should run the canMatch guard so we can register multiple wildcard routes (same behavior like the workaround bellow).
(Personally I use this for multiple slug based features without using a prefix path segment.)
Alternatives considered
To workaround this issue we can provide a matcher that always returns.
const routes: Routes = [
{ path: '', component: Page1, canMatch: [() => true] },
{
matcher: (segments: UrlSegment[]) => ({ consumed: segments }),
component: Page2,
canMatch: [
(route: Route, segments: UrlSegment[]) => segments.toString() === 'page2',
],
},
{
matcher: (segments: UrlSegment[]) => ({ consumed: segments }),
component: Page3,
canMatch: [
(route: Route, segments: UrlSegment[]) => segments.toString() === 'page3',
],
},
];
Stackblitz sample: https://stackblitz.com/edit/angular-bg6fca?file=src%2Fmain.ts
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P4A relatively minor issue that is not relevant to core functionsA relatively minor issue that is not relevant to core functionsarea: router