在我的路由器配置中,我在路径 'dashboard'
下配置了 DashboardComponent
,并且我想在没有指定路径时自动将用户重定向到此路由(空路径,所以只需 /
) .
这是我的代码:
const appRoutes: Routes = [
{ path: '', redirectTo: 'dashboard'},
{ path: 'dashboard', component: DashboardComponent },
/* other routes... */
];
未处理的承诺拒绝:路由'{path:“”,redirectTo:“dashboard”}'的配置无效:请提供'pathMatch' . 'pathMatch'的默认值是'prefix',但通常意图是使用'full'
1 回答
问题是缺少空路线的
pathMatch
属性,默认为prefix
.但是在这种情况下, pathMatch 值应设置为 full :
原因如下:
有关更多详细信息,请参阅官方文档:https://angular.io/guide/router#redirecting-routes