标题已经说明了一切:你能使用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'
则可以正常运行路由。那么有没有办法在
redirectTo
中使用相对路由呢?
编辑 整个路由如下:
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' },
] },
main.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' },
] },