我已经设置了以下routing system个
export const MyRoutes: Routes = [
{path: '', redirectTo: 'new', pathMatch: 'full'},
{path: ':type', component: MyComponent}
];
有以下navigation system个
goToPage('new');
goToPageNo('new', 2);
goToPage(type) {
this.router.navigate([type]);
}
goToPageNo(type, pageNo) {
this.router.navigate([type], {queryParams: {page: pageNo}});
}
示例URL如下所示
http://localhost:3000/new
http://localhost:3000/new?page=2
http://localhost:3000/updated
http://localhost:3000/updated?page=5
Sometimes they have 100 queryParams页
现在我需要读这两本书
ngOnInit(): void {
this.paramsSubscription = this.route.params.subscribe((param: any) => {
this.type = param['type'];
this.querySubscription = this.route.queryParams.subscribe((queryParam: any) => {
this.page = queryParam['page'];
if (this.page)
this.goToPageNo(this.type, this.page);
else
this.goToPage(this.type);
})
})
}
ngOnDestroy(): void {
this.paramsSubscription.unsubscribe();
this.querySubscription.unsubscribe();
}
现在,这并没有像预期的那样起作用,访问没有queryParams的页面是可行的,然后我访问带有queryParams的页面"goToPageNo"会被多次调用,因为我在route params中订阅queryParams.
我看过ANGLING 2文档,它们没有任何同时实现both route params and queryParams订阅的示例或代码.
有什么方法可以做到这一点吗?有什么建议吗?