[英]Parent resolver is not called on child lazy loaded routes
I am trying to set side bar routes based on different user role privileges.我正在尝试根据不同的用户角色权限设置侧栏路由。 The code for setting side bar routes is in site-resolver service.设置侧栏路由的代码在站点解析器服务中。 Which I have called in parent path which I think should be also called for its child routes.我在父路径中调用了它,我认为它的子路径也应该被调用。 But instead, this resolver is getting called only when I refresh the particular child route.但是,只有当我刷新特定的子路由时才会调用这个解析器。
Here's the example of my site-routing service:这是我的站点路由服务的示例:
{
path: ':siteId',
resolve: { site: SiteResolverService },
children: [
// ... other child routes
{
path: 'jsa-training-user-assigned-jsa',
loadChildren: () => import('../jsa-quiz/jsa-quiz.module').then(m => m.JsaQuizModule),
canActivate: [RoleGuardService],
data: { expectedRole: [UserRole.SystemAdmin, UserRole.JsaCreator, UserRole.SiteAdmin, UserRole.PasscodeUser] },
runGuardsAndResolvers: 'always'
},
// ... other child routes
]
here in this route i want the resolver to get called without refreshing, so i have tried below, but not working.在这条路线中,我希望解析器在不刷新的情况下被调用,所以我在下面尝试过,但没有工作。
runGuardsAndResolvers: 'always' runGuardsAndResolvers: '总是'
The resolver is called when you refresh a child route because the whole route tree is triggered, while accessing a child route from a parent will only trigger the child route.刷新子路由时会调用解析器,因为触发了整个路由树,而从父路由访问子路由只会触发子路由。
You can still get the result of the parent resolver in the child component by accessing the route.parent
:您仍然可以通过访问route.parent
来获取子组件中父解析器的结果:
Child component.ts子组件.ts
import { ActivatedRoute } from '@angular/router';
constructor(private route: ActivatedRoute) {}
ngOnInit() {
console.log(this.route.parent.snapshot.data);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.