angular - Angular 8 cannot match nested route
问题描述
I'm using Angular 8 and am having trouble trying to get a nested route to work. The error I get is:
core.js:6014 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'product/colours'
I have the AppComponent HTML which loads my child component 'product' without issue.
app.component.html
<router-outlet></router-outlet>
Inside my 'product' component I want to include a nested component called 'colours'.
colours.component.html
<a routerLinkActive="is-active" routerLink="colours">Colours</a>
<router-outlet name="nested"></router-outlet>
I added a new nested route like this:
app-routing.module.ts
{
path: 'product',
component: ProductComponent,
children: [
{
path: 'colours',
component: ColoursComponent,
outlet: 'nested'
}
]
}
Any advice?
解决方案
使用该RouterLink
属性时,默认情况下它路由到主路由器。您的主路由器上没有product/colours
路由。
你必须让RouterLink
属性知道你想使用哪个插座(如果不是主要的)
<a
routerLinkActive="is-active"
[routerLink]="[{ outlets: { nested: ['colours'] } }]"
>
Colours
</a>
您可以在Angular 文档中找到有关辅助路线导航的更多信息
推荐阅读
- php - 使用队列(数据库)时没有重叠的laravel调度程序
- php - 这样的问题怎么可能发生:一个整数是非数字的?
- hyperledger-composer - 在 WSL (ubuntu 16.04) 上启动 fabric-composer 时 Docker 容器退出 (1) 错误
- c# - VB 到 C# 的替换
- javascript - 在 BluePrism 中使用 JavaScript 从网页获取数据
- android - 通过引用另一种样式来覆盖风味中的自定义属性
- python - 带有 LIKE 子句的 Pyscopg2 SQL 注入安全性
- python - 在python中迭代两个相关循环的有效方法
- java - Java Servlet - 未从请求对象接收到参数名称和值
- ios - 上传期间 Xcode 无效签名问题