我有一个有以下路线的应用程序:
导航到/root/foo或/root/bar将分别计算值X和重定向到/root/foo/(outlet:X)或/root/bar/(outlet:X)。
是否有一种方法可以实现一个保护,从而防止从/root/foo点击到/root/foo/(outlet:X)的路由器链接?
发布于 2018-09-26 21:42:47
您可以实现canDeactivate保护,检查当前和目标urls,并在特定情况下阻止导航。
发布于 2018-09-27 17:57:42
我通过使用CanDeactivate保护程序(但在子组件上)成功地使它正常工作。
路由示例:{ path: 'root/foo', component: ListComponent, children: [ { path: ':id', canDeactivate: [CanNavigateToParentRouteGuard], component: ChildComponent, outlet: 'outlet' } ] },保卫:canDeactivate(component: ChildComponent, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState?: RouterStateSnapshot): boolean { return !currentState.url.startsWith(nextState.url); }
https://stackoverflow.com/questions/52525719
复制相似问题