英文:
Angular : Best way to check queries parameters for all routes
问题
我想检查所有路由的所有查询参数。
我不想使用守卫,因为检查可能会很长。
我想在导航后检查,例如在AfterViewInit中。
如何最好地检查所有路由的所有查询参数?
谢谢。
英文:
I would like to check all queries parameters for all route.
I dont want to use the guard because the checking may be long.
I would like to check after navigation for example in AfterViewInit.
What is the best way to check all queries parameters for all route ?
Regards
答案1
得分: 1
Sure, here's the translated code:
尝试 ActivatedRoute:
constructor(private route: ActivatedRoute) {}
在生命周期钩子中:
this.route.queryParams.subscribe((params) => {
console.log(params);
})
英文:
Try ActivatedRoute:
constructor(private route: ActivatedRoute) {}
In the lifecycle hook:
this.route.queryParams.subscribe((params) => {
console.log(params);
})
答案2
得分: 0
你可以注入 Router 并记录它的 config 属性。但这只适用于预加载的模块,即:
export class AppComponent {
constructor(private router: Router) {
console.log(router.config)
}
}
英文:
You can inject Router and log it's config prop. But its gonna work only for preloaded (not ladyloaded) modules, i.e.
export class AppComponent {
constructor(private router: Router) {
console.log(router.config)
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论