在应用程序中,我希望在操作中导航到home/contract-view/10
。试过
this.router.navigateToRoute(`home/contract-view`, { id: 10}, { absolute: true });
以Route home/contract-view not be found
另一次尝试:
this.router.navigate(`#/home/contract-view`, { id: 10});
以Route not found: contract-view(…)
失败
怎么做到这一点?
App.ts:
configureRouter(config: RouterConfiguration, router: Router) {
config.title = 'Contracts Portal';
config.map([
{ route: ['', 'dummy'], name: 'dummy', moduleId: 'dummy', nav: false, title: 'Dummy', settings: { pos: 'left' } },
{ route: 'home', name: 'home', moduleId: 'home', nav: true, title: 'Home', settings:{pos: 'left', class: 'home' }, auth: true },
]);
this.router = router;
}
Home.ts:
configureRouter(config: RouterConfiguration, router: Router) {
config.map([
{ route: ['', 'contract-view/:id'], name: 'contract-view', moduleId: 'contract-view', nav: true, title: 'Contract' },
{ route: 'doc-view/:id', name: 'doc-view', href:'doc-view', moduleId: 'doc-view', nav: true, title: 'Document' },
]);
this.router = router;
this.router.refreshNavigation();
}
答案 0 :(得分:35)
首选解决方案是使用您在路由器中配置的命名路由。
this.router.navigateToRoute('contract-view', {id: 10});
答案 1 :(得分:7)
你有家里的路由器'配置了contract-view/:id
,因此您需要this.router.navigate('home/contract-view/10')
。并尝试删除this.router.refreshNavigation()
答案 2 :(得分:0)
谢谢@valichek,
只需要让type
让它工作。开头的额外this.router.navigate('/home/contract-view/10')
产生了不同。