如何使用angular中激活的路由器从url访问查询参数?
我需要使用激活路由器访问带有查询参数的当前url如何使用angular中激活的路由器从url访问查询参数?,angular,angular-router,angular-activatedroute,Angular,Angular Router,Angular Activatedroute,我需要使用激活路由器访问带有查询参数的当前url constructor(private router: Router, private route: ActivatedRoute) { } ngOnInit() { this.router.events.pipe( filter((event: RouterEvent) => event instanceof NavigationEnd && event.u
constructor(private router: Router,
private route: ActivatedRoute) {
}
ngOnInit() {
this.router.events.pipe(
filter((event: RouterEvent) => event instanceof NavigationEnd && event.url.startsWith('/resources'))
).subscribe(() => {
console.log(this.route.snapshot.params)
})
}
当我访问我的url时,http://localhost:4200/web/#/resources/sharepoint;siteId=docs;显示名称=测试;resourceId=4
this.route.snapshot.params
打印一个空数组。如何访问查询参数“resourceId”
我尝试了
this.route.snapshot.queryParams
,但它仍然打印一个空数组。使用this.router.url阅读,然后拆分它
constructor(private router: Router) {
var url=this.router.url;
var params=url.split(";");
var resourceId=params[params.length-1].split("=")[1];
}