在app.ts中,我希望导航到home/contract-view/10 on a action。已尝试
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();
}发布于 2016-03-12 20:09:14
您在'home‘中有配置了contract-view/:id的路由器,因此您需要this.router.navigate('home/contract-view/10')。并尝试删除this.router.refreshNavigation()
发布于 2016-05-02 08:06:03
首选解决方案是使用您在路由器中配置的命名路由。
this.router.navigateToRoute('contract-view', {id: 10});发布于 2016-03-13 15:22:23
谢谢@valichek,我只需要把它变成this.router.navigate('/home/contract-view/10')就行了。开始时额外的/起到了作用。
https://stackoverflow.com/questions/35955734
复制相似问题