2016-11-23 35 views
0

我想在我的AddUserComponent中提交表單之後回到我的父組件。如何返回到Angular 2中的父組件

我的網址應該改變:/video/1/user/video/1

我試圖

this._router.navigate(['../../video'],{ relativeTo: this.route }) 
this._router.navigate(['../../video',{video_id:1}],{ relativeTo: this.route }) 

,但它不工作。

我的路線:

export const routes = [ 
    { path: '', component: VideosComponent }, 
    { 
    path: 'video/:video_id', 
    children :[ 
     { path: '', component: VideoComponent }, 
     { 
      path: 'user', 
      children :[ 
       { path: '', component: AddUserComponent }, 
       { path: ':user_id', 
       children :[ 
        { path: '', component: EditUserComponent} 
       ] 
       } 
      ] 
     }, 
    ] 
} 
]; 

任何想法?

+1

你檢查[這個答案](http://stackoverflow.com/a/38810729/2435473)? –

回答

0

這些應該工作

this._router.navigate(['../../video',1],{ relativeTo: this.route }) 
this._router.navigate(['../../video/' + 1],{ relativeTo: this.route }) 
this._router.navigate(['../../video/1'],{ relativeTo: this.route }) 

或絕對

this._router.navigate(['/video',1]) 
+0

感謝但url看起來像視頻/ 1 /用戶/視頻/ 1。我想擺脫'用戶'。 –

+0

聽起來像缺少''中的(或「APP_BASE_HREF」的提供程序。http://stackoverflow.com/questions/34535163/angular-2-router-no- base-href-set/34535256#34535256 –

+0

不幸的是,它不起作用。 –

相關問題