angular - :id 路由覆盖其他路由
问题描述
我有以下路线:
const routes: Routes = [
{ path: '', component: UserComponent, children: [
{ path: '', component: LoginComponent },
{ path: 'signup', component: SignupComponent }
]},
{ path: 'dashboard', component: MainComponent, children: [
{ path: '', component: DashboardComponent, children: [
{ path: '', redirectTo: '0', pathMatch: 'full' },
{ path: '0', component: NoListComponent },
{ path: ':id', component: ListComponent },
]},
{ path: 'createlist', component: CreateListComponent },
{ path: 'create', component: CreateTaskComponent }
]},
];
不知何故,当我调用routerLink="dashboard/create"
or时routerLink="dashboard/createlist"
,ListComponent (:id) 显示为没有内容,但不是 CreateListComponent 或 CreateTaskComponent。
解决方案
您需要更改路由配置,如下所示:
{
path: 'dashboard',
component: MainComponent,
children: [{
path: '',
component: DashboardComponent,
children: [{
path: '',
redirectTo: '0',
pathMatch: 'full'
},
{
path: '0',
component: NoListComponent
},
{
path: 'createlist',
component: CreateListComponent
},
{
path: 'create',
component: CreateTaskComponent
},
{
path: ':id',
component: ListComponent
}
]
}]
}
这是必需的,因为/createlist
并且/create
都是/dashboard
. 请注意上面列出的路径的顺序。
推荐阅读
- arrays - 在 Swift 中搜索和替换二维数组中的字符串
- ios - 切换 ViewController 并向下滚动后,导航栏标题从小文本切换到大文本?
- php - laravel foreach input radiobutton displayed incorrectly
- oauth-2.0 - using third-party identity provider with Azure AD and MSAL.js
- php - Php Redis extension not working on wampserver windows10
- apache-kafka - Consume data from Kafka
- kubernetes - Get names of all deployment configs with no running pods
- postgresql - Time is being stored in postgres database without timezones even though I provide them to sequelize
- python-3.x - Convert the Powershell script to Python 3
- r - Topic modeling issues with R