我的路由器功能“导航”有问题,在我的AppComponent中我有:
@RouteConfig([
{path:'/home', name: 'Home', component: HomeComponent, useAsDefault: true, data: {user: null}},
{path:'/dashboard', name: 'Dashboard', component: DashboardComponent}
])
在我的HomeComponent中,我正在尝试这样做:
...
constructor(private _router:Router){}
changePage(){
this._router.parent.navigate(["Dashboard"]); // It fails
}
...
它没有发送给'/ dashboard',这是正常的吗?
答案 0 :(得分:5)
我终于找到了!它正在使用:
changePage() {
this._router.navigate(["../Dashboard"]);
}
感谢您帮助我
答案 1 :(得分:4)
为什么要使用父母?它应该是this._router.navigate(["Dashboard"]);
答案 2 :(得分:1)
router.navigate是一种将路径作为参数并导航到该特定路径并加载组件的方法,我希望它能够正常工作。
number
答案 3 :(得分:0)
错误讯息是什么?
另外,为什么使用this._router.parent.navigate
而不是简单this._router.navigate..
?
答案 4 :(得分:0)
您可以尝试以下操作来使用AppComponent
组件中定义的路由:
changePage() {
this._router.navigate(["/Dashboard"]);
}