【发布时间】:2017-09-25 04:54:21
【问题描述】:
我是 angular2 的新手。我试图了解如何在特定模板中使用多个 <router-outlets>。我在这里进行了许多 QA,但无法解决我的错误。
router.module.ts
const routes: Routes = [
{
path: '',
redirectTo: 'one',
pathMatch: 'full'
},
{
path: 'two',
component: ClassTwo, children: [
{
path: 'three',
component: ClassThree,
outlet: 'nameThree',
},
{
path: 'four',
component: ClassFour,
outlet: 'nameFour'
}
]
},];
component1.html
<h3>In One</h3>
<nav>
<a routerLink="/two" class="dash-item">...Go to Two...</a>
<a routerLink="/three" class="dash-item">... Go to THREE...</a>
<a routerLink="/four" class="dash-item">...Go to FOUR...</a>
</nav>
<router-outlet></router-outlet> // Successfully loaded component2.html
<router-outlet name="nameThree" ></router-outlet> // Error: Cannot match any routes. URL Segment: 'three'
<router-outlet name="nameFour" ></router-outlet> // Error: Cannot match any routes. URL Segment: 'three'
component2.html
<h3>In two</h3>
component3.html
<h3>In three</h3>
component4.html
<h3>In four</h3>
当我点击 ...转到两个... 在两个 被打印出来。 但是点击其他两个链接会给我错误无法匹配任何路线
【问题讨论】:
-
路由器出口是另一个ro,你必须用导航器处理它们
-
我应该如何以及在哪里给先生? @RomanCpan>
-
我认为它在router。