如何使用router.navigate上app.component的OnInit的angular2

问题描述:

我试图导航路线上app.component.ts在角2 这里的plunkr链接:http://plnkr.co/edit/inqrSB如何使用router.navigate上app.component的OnInit的angular2

我试图让这个working:

ngOnInit(){ 
    if(this._vehicleService.isAuth()) 
    { 
     this.shownavBar=true; 
     this._router.navigate('/characters') //how can i get this 
    } 
    } 

routeConfig定义在同一个组件中。有人可以建议我解决这个问题。

这里的结果:

只需改变使用这样的:

this._router.navigate(['Characters']) //how can i get this 
+1

感谢的人,也没有工作。 –

+0

我也试图在角2.0版最终版中从路由器导入的路由的帮助。没有错误,没有重定向,并且根据最新版本@RouteConfig已从@ angular/route中弃用。帮帮我 – AnkitJ

+0

@AnkitJ请用蹦床问一个新问题,以便我们可以重现您的问题。 – echonax

this._router.navigate(["Name of your Component"]) 

OR

this._router.navigateByUrl("/where you want")