I’m trying to figure out how to implement a route and capture a route parameter, but restrict the parameter values so as not to interfere with other routes.
This is what I want, where the timeline
route will be any of 5 matches in the first route, and I need to know what that value is:
configureRouter(config: RouterConfiguration, router: Router) {
this.router = router;
config.map([
{ route: ['', 'all', 'posts', 'comments', 'likes'], name: 'timeline', moduleId: PLATFORM.moduleName('./timeline/index'), nav: false, title: 'Timeline'},
{ route: [':slug'], name: 'content-post', moduleId: PLATFORM.moduleName('./content-post.component'), nav: false, title: 'Post'}
]);
}
It would be nice if parameterized routes can defined restricted values, something like:
config.map([
{ route: ['', ':viewType?: ["all", "posts", "comments", "likes"]'], name: 'timeline', moduleId: PLATFORM.moduleName('./timeline/index'), nav: false, title: 'Timeline'},
{ route: [':slug'], name: 'content-post', moduleId: PLATFORM.moduleName('./content-post.component'), nav: false, title: 'Post'}
]);
In the sub route views I can pluck that out:
./timeline/index
:
configureRouter(config: RouterConfiguration, router: Router) {
this.router = router;
config.map([
// viewType = '', 'all', 'posts', 'comments', 'likes'
{ route: ['', 'all', 'posts', 'comments', 'likes'], name: 'home', moduleId: PLATFORM.moduleName('./timeline.component'), nav: false, title: 'Muckraker' }
]);
}
./timeline/timeline.component
:
async activate(params: any, routeConfig: RouteConfig): Promise<any> {
this.viewType = params.viewType || 'all';
return this.doStuff();
}
determineActivationStrategy() {
return activationStrategy.invokeLifecycle;
}