[英]Angular 2 router navigate function not working
我的路由器功能“导航”有问题,在我的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',这是正常的吗?
我终于找到了! 它正在与:
changePage() {
this._router.navigate(["../Dashboard"]);
}
感谢你们对我的帮助
为何使用父母? 它应该是this._router.navigate(["Dashboard"]);
router.navigate是一个方法,它将路径作为参数并导航到该特定路径并加载组件,我希望它能工作。
constructor(private _router:Router){}
changePage(){
this._router.navigate(["dashboard"]);
}
什么是错误消息?
另外为什么使用this._router.parent.navigate
而不是简单的this._router.navigate..
?
您可以尝试以下方法来使用AppComponent
组件中定义的路由:
changePage() {
this._router.navigate(["/Dashboard"]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.