我已经阅读了所有关于此问题的帖子,但是没有一篇对我有用。
我有一个应用程序模块和一个路由模块,没有其他“模块”。 我发现以下情况:
- 标准路由可以从任何组件链接
- 具有命名出口的路线只能从默认应用程序组件链接,而不是其他组件
- 使用routerLink从除应用程序组件以外的任何组件链接到命名出口会导致“错误:无法匹配任何路由。 URL段:”
我的路由如下...
{path: 'hellocontent', component: ContentHelloWorldComponentComponent,
pathMatch: 'full', outlet: 'helloc'},
The routerLink is...
<a [routerLink]="[{ outlets: { helloc: ['hellocontent'] } }]">action</a>.
我的路由器插座...
<router-outlet name="helloc"></router-outlet>
<router-outlet></router-outlet>
在标准的angular app.component.html中,该路由器链接完美地工作,但在任何其他组件中都不行。它总是会导致“错误:无法匹配任何路由。URL段:”。
只要我删除了命名出口,并将routerLink更改为...<a routerLink="hellocontent">action</a>
在app组件中,或者在另一个组件中 <a routerLink="/hellocontent">action</a>
,它就可以完美地工作,但仅适用于主出口。
由于这可能很重要,因此我从中链接的组件当然也在其自己的路由中定义,例如...
{path: 'hello-world', component: HelloWorldComponentComponent}
这是预期的行为吗?即仅能从定义它们的组件中访问命名出口?很奇怪,因为我的大部分html包装器都在app.component.html中,但除了主要出口之外,其他任何出口都无法从另一个组件中使用。