-
Notifications
You must be signed in to change notification settings - Fork 27k
Description
I'm submitting a ... (check one with "x")
[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
Only a function can be set as the urlMatcher of a route.
const routes = [{
urlMatcher: (segments: UrlSegment[], segmentGroup: UrlSegmentGroup, route: Route) => {
/* Do stuff */
},
component: MyComponent,
}]
Expected behavior
A DI-resolved service or function can be set as the urlMatcher allowing for further injection. I'd expect this to work in an identical way to how the resolver properties can either be services that implement the Resolve<T> interface OR can be an inline resolve() function.
const routes = [{
urlMatcher: MyUrlMatcherService,
component: InterruptComponent,
},
{
path: ":id",
component: ListComponent, /* Contains a <router-outlet> for routing children */
children: [ /*children with sub-paths for deep linking */ ]
}];
@Injectable()
export class MyUrlMatcherService {
constructor(myStateService:MyStateService){}
matchUrl(segments: UrlSegment[], segmentGroup: UrlSegmentGroup, route: Route):UrlMatchResult {
if (!this.myStateService.isInterrupt) return null;
/* Do matching stuff */
}
}
Minimal reproduction of the problem with instructions
N/A
What is the motivation / use case for changing the behavior?
My use case is that InterruptComponent should resolve if some system state (managed by a service) is currently true. If not, I want to skip this route an let other routes attempt matching. In my case I want to greedily consume the entire sub-path and display a specific component, but only in certain circumstances.
Please tell us about your environment:
N/A
- Angular version: 4.X
- Browser: N/A
- Language: TypeScript 2.2+
- Node (for AoT issues): N/A