How to use a wild card for part of the path in Angular router? -
i have following routing setup.
const routes: routes = [ { path: "submenu1", component: submenucomponent, outlet: "menus" }, { path: "submenu2", component: submenucomponent, outlet: "menus" }, { path: "submenu3", component: submenucomponent, outlet: "menus" }, ... ];
i tried use wild card **
match starting submenu in following way. sadly, seem not match way , no routing @ all.
const routes: routes = [ { path: "submenu**", component: submenucomponent, outlet: "menus" }, //{ path: "submenu1", component: submenucomponent, outlet: "menus" }, //{ path: "submenu2", component: submenucomponent, outlet: "menus" }, //{ path: "submenu3", component: submenucomponent, outlet: "menus" }, ... ];
how do that?
how following ?
const routes: routes = [ { path: "submenu1", component: submenucomponent, outlet: "menus" }, { path: "submenu2", redirectto: 'submenu'}, { path: "submenu3", redirectto: 'submenu'}, ];
or if doesn't bother put router listener on app component:
ngoninit() { if (isplatformbrowser) { this.routersubscription = this.router.events .filter(event => event instanceof navigationend) .subscribe(() => { if(this.router.url.startswith('submenu'){ this.router.navigate(['submenu1']); }; }); } } ngondestroy() { this.routersubscription.unsubscribe(); }
wiki
Comments
Post a Comment