错误:无法匹配任何路由。网址细分:' home'

时间:2017-07-27 20:01:28

标签: angular

我刚开始学习路由器角度,我无法使用命名插座,请看下面的代码

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'

1 个答案:

答案 0 :(得分:1)

您必须指定插座名称

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