2017-07-27 79 views
0

我剛開始學習的角度路由器和我無法使用命名出口,請看看下面的代碼錯誤:無法匹配任何路線。 URL段:「家」

const routes: Routes = [{ 
    path: "about", 
    component : AboutComponent, 
    children : [{ 
      path : "contact", 
      component: ContactComponent }, { 
      path : "message", 
      component: MessageComponent }, { 
      path : "", 
      component: ContactComponent }, 
      ]}, 
    { 
    path: "home", 
    component : HomeComponent 
    // outlet : "main" When I add this, it is not working 
    },{ 
    path: "", 
    component : HomeComponent, 
    outlet : "main" 
    }]; 

app.component.html 
------------------ 
<h1>The Header</h1> 
<a routerLink="home">Home</a> 
<a routerLink="about">About</a> 
<router-outlet></router-outlet> 
<router-outlet name="main"></router-outlet> 
<h1>The footer</h1> 

上面的代碼工作正常,但當我加出口path:'home',它說 Error: Cannot match any routes. URL Segment: 'home'

+0

如果你剛開始學習路由,你可能有興趣在我的課程:「角路由」:https://app.pluralsight.com/library/courses/角度路由/目錄它涵蓋了許多不同類型的路由。您可以免費註冊一週。 – DeborahK

回答

1

您必須指定的出口名稱

<a [routerLink]="[{ outlets: { main: ['home'] } }]">Home</a> 
+0

無法正常工作。你可以告訴我fiidler – user3205479

+0

這是官方的Angular路由模塊的示例/課程:https://embed.plnkr.co/?show=preview。 'app-routing.module.ts'聲明主要路由。其中一個('compose')用'outlet'聲明。然後轉到'app.component.ts'。這裏使用該路線,通過'Contact'。 –

相關問題