gpt4 book ai didi

Angular2 路由 : redirectTo a relative url

转载 作者:行者123 更新时间:2023-12-04 17:54:30 25 4
gpt4 key购买 nike

一切都在标题中:您可以使用 redirectTo 属性重定向到相对 URL 吗?

我的(简化的)路由如下:

{path: 'login', children: []},
{path: '', children: [ // made here for future guards
{path: 'admin', children: [
{path: 'dashboard', children: []}
{path: '', redirectTo: 'dashboard'}
]}
]},
{path: '', redirectTo: 'login', pathMatch: 'full'}

我的路由运行良好,除了当我想访问 URL/admin/ 时出现错误,提示仪表板未知。但是,使用 redirectTo: 'admin/dashboard' 路由有效。

那么有没有办法通过 rediretcTo 使用相对路由?

编辑 整条路线:

app.module

{ path: 'login', component: LoginComponent, children: [] },
{ path: 'signup', component: SignupComponent, children: [] },
{ path: '', redirectTo: '/login', pathMatch: 'full' },
...loggedRoutes

logged.module

{ path: 'logged', component: LoggedComponent, children: [
{ path: 'profile', component: ProfileComponent, children: [] },
...adminRoutes,
...mainRoutes
] },

admin.module

{ path: 'admin', component: AdminComponent, children: [
{ path: 'dashboard', component: DashboardComponent, children: [] },
{ path: 'validation/:objectid', component: ValidationComponent, children: [] },
{ path: '', redirectTo: '/logged/admin/dashboard' },
] },

ma​​in.module

{ path: 'main', component: MainComponent, children: [
{ path: 'error', component: ErrorComponent, children: [] },
{ path: 'last', component: LastComponent, children: [] },
{ path: 'process', component: ProcessComponent, children: [] },
{ path: 'crt', component: CrtComponent, children: [] },
{ path: '', redirectTo: '/logged/main/error' },
] },

最佳答案

您只需将 pathMatch: 'full' 添加到您的重定向路由中,它就会按照您的预期工作。

{path: 'login', children: []},
{path: '', children: [ // made here for future guards
{path: 'admin', children: [
{path: 'dashboard', children: []}
{path: '', redirectTo: 'dashboard', pathMatch: 'full'} // <-- ADDED here
]}
]},
{path: '', redirectTo: 'login', pathMatch: 'full'}

关于Angular2 路由 : redirectTo a relative url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41489358/

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