Angular.Router.navigate 无法使用 queryParams 导航到子路由
А已经尝试过:
this.router.navigateByUrl('/desktop/search?q=folder'));
this.router.navigate(['desktop', 'search'], { queryParams: {q: 'folder'} });
this.router.navigate(['desktop/search'], { queryParams: {q: 'folder'} });
我的路线:
{
path: 'desktop',
component: FavoritesPageComponent,
children: [
{ path: 'desktop-admin', component: DesktopAdminComponent },
{ path: 'favorites', component: FavoritesBodyMainComponent },
{ path: 'sessions', component: SessionsComponent },
{ path: 'search', component: FavoritesBodySearchComponent },
{ path: 'shared_with_me', component: FavoritesBodySharedComponent },
{ path: 'recycle', component: FavoritesBodyRecycleComponent }
]
}
当我尝试导航到“桌面/搜索?q=文件夹”时,出现以下错误:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'desktop/search%3Bq%3D%25D0%25BF%25D0%25B0%25D0%25BF%25D0%25BA%25D0%25B0'
怎么了?有没有办法使用带有普通查询参数的子路由,比如
.../desktop/search?q=folder
this.route.queryParams.subscribe(params => {
console.log('params['q']: ', params['q']);
});