在我的应用程序中,我有一个不带路由模块的核心模块和一个带路由模块的功能模块。在我的功能模块的一个组件中,我可以通过在构造函数中使用以下内容来访问路由参数:
this.route.params.subscribe((params: Params) => {
console.log("params['searchTerm']");
console.log(params['searchTerm']);
this.searchTerm = params['searchTerm'];
});现在,在我的Core模块的一个组件中,我也想使用上面的代码来访问params。因为路由是在功能模块路由模块中定义的,所以当我尝试访问参数时,我只是没有定义。
我如何才能实现访问参数?
发布于 2018-07-11 19:59:55
这是可能的解决方案之一:
constructor(private route: ActivatedRoute, private router: Router) {
router.events.subscribe((e) => {
let currentRoute = this.route.root;
while (currentRoute.children[0] !== undefined) {
currentRoute = currentRoute.children[0];
}
if (e instanceof NavigationEnd) {
// you can do it for exact phase
console.log(currentRoute.snapshot.params);
}
});
}发布于 2017-03-24 21:02:46
我也有同样的情况。路由在功能模块中定义,核心模块的布局组件可以访问params。它起作用了!确保您:
https://stackoverflow.com/questions/42692359
复制相似问题