[英]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.