[英]Angular 2 router navigate function not working
I have a problem with the router function "navigate", in my AppComponent I have : 我的路由器功能“导航”有问题,在我的AppComponent中我有:
@RouteConfig([
{path:'/home', name: 'Home', component: HomeComponent, useAsDefault: true, data: {user: null}},
{path:'/dashboard', name: 'Dashboard', component: DashboardComponent}
])
In my HomeComponent, I am trying to do this : 在我的HomeComponent中,我试图这样做:
...
constructor(private _router:Router){}
changePage(){
this._router.parent.navigate(["Dashboard"]); // It fails
}
...
It doesn't send me at '/dashboard', is this normal ? 它没有发送给'/ dashboard',这是正常的吗?
I have finally found ! 我终于找到了! It's working with : 它正在与:
changePage() {
this._router.navigate(["../Dashboard"]);
}
Thank you for helping me 感谢你们对我的帮助
why using parent ? 为何使用父母? it should be this._router.navigate(["Dashboard"]);
它应该是this._router.navigate(["Dashboard"]);
router.navigate is a method which take path as a parameter and navigate to that particular path and load component, I hope it will work. router.navigate是一个方法,它将路径作为参数并导航到该特定路径并加载组件,我希望它能工作。
constructor(private _router:Router){}
changePage(){
this._router.navigate(["dashboard"]);
}
What is the error message ? 什么是错误消息?
Also why using this._router.parent.navigate
rather than simply this._router.navigate..
? 另外为什么使用this._router.parent.navigate
而不是简单的this._router.navigate..
?
You could try the following to use a route defined in the AppComponent
component: 您可以尝试以下方法来使用AppComponent
组件中定义的路由:
changePage() {
this._router.navigate(["/Dashboard"]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.