Ara*_*per 7 angular angular-router
错误:路由 '{path:"teams/", redirectTo:"all"}' 的配置无效:请提供 'pathMatch'。'pathMatch' 的默认值是 'prefix',但通常意图是使用 'full'。
这是错误按摩。
这是我在 app.module.ts 上的语法:
const routes = [
{ path: 'teams', component: TabsComponent, children: [
{ path: '', redirectTo: 'all', pathMacth: 'full' },
{ path: ':side', component: ListComponent }
] },
{ path: 'new-team', component: CreateTeamComponent },
{ path: '**', redirectTo: '/teams' }
Run Code Online (Sandbox Code Playgroud)
];
为什么我还是有错误??
默认情况下,Angular 通过前缀匹配路径。这意味着,以下路由将匹配 /recipes 和仅 /
{ path: '', redirectTo: '/somewhere-else' }
实际上,Angular 会在这里给你一个错误,因为这是一个常见的问题:这条路线现在总是会重定向你!为什么?
由于默认匹配策略是 "prefix" ,Angular 会检查您在 URL 中输入的路径是否以路由中指定的路径开头。当然,每条路径都以 '' 开头(重要的是:那不是空格,它只是“什么都没有”)。
要修复此行为,您需要将匹配策略更改为 "full" :
{ path: '', redirectTo: '/somewhere-else', pathMatch: 'full' }
现在,只有在完整路径为 '' 的情况下,您才会被重定向(因此,只有在此示例中您的路径中没有其他内容时)。
| 归档时间: |
|
| 查看次数: |
10565 次 |
| 最近记录: |