我正在尝试对不同的模块进行延迟加载,并且试图将路由前缀与加载模块进行匹配。但它不起作用,它适用于确切的URL,但不适用于前缀。我正在使用角度6.1。
此代码无效
{
path: 'account',
component: AuthComponent,
children: [
{
path: '',
loadChildren: './modules/auth/auth.module#AuthModule'
}
{
path: '**',
loadChildren: './modules/auth/auth.module#AuthModule'
}
]
},
,此代码可以正常工作
{
path: 'account',
component: AuthComponent,
children: [
{
path: '',
loadChildren: './modules/auth/auth.module#AuthModule'
},
{
path: 'login',
loadChildren: './modules/auth/auth.module#AuthModule'
},
{
path: 'register',
loadChildren: './modules/auth/auth.module#AuthModule'
},
{
path: '**',
loadChildren: './modules/auth/auth.module#AuthModule'
}
]
},
我必须为加载模块映射每条路线吗?
这些是我要加载的模块中的路由。
const routes = [
{
path: '',
component: LoginComponent,
data: {
title: 'login'
}
},
{
path: 'login',
component: LoginComponent,
data: {
title: 'login'
}
},
{
path: 'register',
component: RegisterComponent,
data: {
title: 'register'
}
},
{
path: 'admin/login',
component: LoginComponent,
data: {
title: 'Admin login'
}
}
];
谢谢。
答案 0 :(得分:1)
尝试这样:
{
path: 'account', loadChildren: './modules/auth/auth.module#AuthModule'
},
const routes = [
{
path: '', component: AuthComponent,
},
{
path: 'login',
component: LoginComponent,
data: {
title: 'login'
}
},
{
path: 'register',
component: RegisterComponent,
data: {
title: 'register'
}
},
{
path: 'admin/login',
component: LoginComponent,
data: {
title: 'Admin login'
}
}
];