gpt4 book ai didi

Angular2设置默认路由

转载 作者:太空狗 更新时间:2023-10-29 17:23:14 25 4
gpt4 key购买 nike

我正在模块中设置我的路由,我想设置默认路由但它失败了

这是路由模块

const appRoutes: Routes = [
{ path: 'login', component: LoginComponent, useAsDefault:true }, //returns an error
{
path: 'dash',
redirectTo:"dashboard"
},

{ path: 'reset-password', component: ResetPasswordComponent },
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
{ path: '**', component: PageNotFoundComponent }
];

以上返回错误

LoginComponent; useAsD...' is not assignable to type 'Route[]'

可能是哪里出了问题

最佳答案

当使用 useAsDefault 时,您需要先让父路由和子路由上的 useAsDefault 出现。所以,不需要 useAsDefault,你可以简单地将 Login 作为默认路由。正如我所看到的,Dashboard 没有导入组件,

const appRoutes: Routes = [
{
path: '',
redirectTo: "/login",
pathMatch: 'full'
},
{ path: 'login', component: LoginComponent },
{ path: 'reset-password', component: ResetPasswordComponent },
{ path: '**', component: PageNotFoundComponent }
];

关于Angular2设置默认路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42155766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com