Angular 2.0路由器。导航不工作
我正在使用Angular 2.0和路由器版本3.0.0。我定义了以下路由配置Angular 2.0路由器。导航不工作,angular,Angular,我正在使用Angular 2.0和路由器版本3.0.0。我定义了以下路由配置 export const onlineRoutes: Routes = [ { path: 'online.html', component:onlineHome }, { path: 'portfolioperformance', component: PortfolioPerformance }, ]; export const onlinerouting = RouterModule.forRoot(on
export const onlineRoutes: Routes = [
{ path: 'online.html', component:onlineHome },
{ path: 'portfolioperformance', component: PortfolioPerformance },
];
export const onlinerouting = RouterModule.forRoot(onlineRoutes,{useHash:false,enableTracing:true});
它成功地路由到online.html路由,但当我尝试使用以下语句路由到“portfolioperformance”时,它不起作用
this.router.navigate(['/portfolioperformance']);
如果我像下面这样使用路由器链接,点击链接就可以了
<li><a [router-link]="['/portfolioperformance']">Start</a></li>
不知道出了什么问题。感谢您的帮助 也许您需要添加
this.router.navigate(…),{relativeTo:currentRoute})代码>谢谢。我尝试了这个,但没有帮助。您已经尝试了routerLink
和this.router.navigate
在同一个组件中,并将构造函数(此当前路由:ActivatedRotue)
传递到relativeTo
?(另见)你解决了这个问题吗?我面临着同样的问题我也有这个问题。routerLink可以工作,但导航和navigateByUrl什么也不做。每次都会调用成功回调。但是,我注意到,如果我在调用中放入一些随机URL,它也会返回成功处理程序,所以我想这是没有用的。
‹Start group›: Router Event: NavigationStart
NavigationStart(id: 1, url: '/portfolioperformance')
NavigationStart {id: 1, url: "/portfolioperformance"}
‹End group›
‹Start group›: Router Event: NavigationStart
NavigationStart(id: 2, url: '/online.html#id_token=XXXXXXXXXXXXXXXXXXXXX"}
‹End group›
Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode.
‹Start group›: Router Event: NavigationCancel
NavigationCancel(id: 1, url: '/portfolioperformance')
NavigationCancel {id: 1, url: "/portfolioperformance", reason: "Navigation ID 1 is not equal to the current navigation id 2"}
‹End group›
‹Start group›: Router Event: RoutesRecognized
RoutesRecognized(id: 2, url: '/online.html#id_token=XXXXXXXXXXXX', state: Route(url:'', path:'') { Route(url:'online.html', path:'online.html') } )