2017-07-27 4 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/角度ルーティング/目次ここでは、さまざまなタイプのルーティングについて説明します。無料で1週間申し込むことができます。 – DeborahK

答えて

1

あなたはちょうどあなたが私のコースに興味がある可能性があり、ルーティングを学習している場合は、

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

は機能しません。フィドラーに私を見せてください – user3205479

+0

Routingモジュールの公式なAngularの例/コースはhttps://embed.plnkr.co/?show=previewです。 'app-routing.module.ts'はメインルートを宣言します。そのうちの1つ( 'compose')は' outlet'で宣言されています。それから 'app.component.ts'に行きます。ここでルートは 'Contact'経由で利用されます。 –

関連する問題