2017-08-31 105 views
0

我工作的一個Angular2應用程序,當我瀏覽到錯誤:無法匹配任何路線。 URL段: '賬戶'

http://localhost:4200/account

我得到

Error: Cannot match any routes. URL Segment: 'account'

我的路線是這樣的:

export const appRoutes: Routes = [ 
    { 
     path: '', component: MyComponent, children: [ 
      { 
       path: '', component: HeaderComponent, outlet: 'header', children: [ 
        { 
         path: 'account', component: AccountComponent, children: [ 
          { path: 'login', component: LoginComponent, outlet: 'login' }, 
          { path: 'signup', component: SignupComponent, outlet: 'signup' }, 
         ] 
        } 
       ] 
      }, 
      { 
       path: '', component: ContentComponent, children: [ 
        { path: '', component: HomeComponent } 
       ] 
      }, 
      { path: '', component: FooterComponent, outlet: 'footer' }, 
     ] 
    }, 
]; 

有什麼想法? 謝謝!

編輯1 以及我創造了這個

export const appRoutes: Routes = [ 
    { 
     path: '', component: MyComponent, children: [ 
      { 
       path: '', component: HeaderComponent, outlet: 'header', children: [ 
        { 
         path: 'account', component: AccountComponent, children: [ 
          { path: '', pathMatch: 'full', component: NotfoundComponent }, 
          { path: 'login', component: LoginComponent }, 
          { path: 'signup', component: SignupComponent }, 
         ] 
        } 
       ] 
      }, 
      { 
       path: '', component: ContentComponent, children: [ 
        { path: '', component: HomeComponent } 
       ] 
      }, 
      { path: '', component: FooterComponent, outlet: 'footer' }, 
      { path: '**', component: NotfoundComponent }, 
     ] 
    }, 
]; 

,並導航到賬戶/登錄,它需要我沒有找到 我失去了什麼?可能與我的路線或結構有關?

+0

你爲什麼在LoginCo上使用命名插座mponent'和'SignupComponent'? –

+0

@GünterZöchbaueri希望能夠在它們之間導航,這是問題嗎? –

+0

應該不需要一個命名的插座來獲取它。命名的網點是用於平行導航。比如在Gmail中,除了郵件文件夾的正常路由之外,撰寫郵件對話框還有自己的菜單和路由。我最後嘗試在路由配置中嘗試命名的插座(而不是從'routerLink'或'router.navigate()'),並且我無法使其工作。 –

回答

0

您不能使用當前的路由配置路由到account

要麼

  • 路線account/loginaccount/signup
  • 添加重定向該路徑導航到的這兩個
  • 一個添加用空路徑
{ 
    path: '', component: MyComponent, children: [ 
     { 
      path: '', component: HeaderComponent, outlet: 'header', children: [ 
       { 
        path: 'account', component: AccountComponent, children: [ 
         { path: '', pathMatch: 'full', component: DummyComponent } 
         { path: 'login', component: LoginComponent }, 
         { path: 'signup', component: SignupComponent }, 
        ] 
       } 
      ] 
     }, 
... 
路由
+0

你可以檢查編輯1 ?,我編輯我的問題 –

+0

'{path:'',component:HomeComponent}'needs'pathMatch:'full'' –

+0

Are you使用'ng-serve'? –

相關問題