问题 我想在访问localhost:4200时重定向到页面,但是要重定向到localhost:4200 /始终登录。
我有2个惰性加载模块,每个惰性模块都有childRoutes,我根本不了解如何始终重定向到登录名。
app.routing.module.ts
const routes: Routes = [
{ path: '', redirectTo: 'pages', pathMatch: 'full' },
{
path: 'pages',
loadChildren: './static/static.module#StaticModule'
},
{
path: 'auth',
loadChildren: './core/auth/auth.module#AuthModule',
},
{ path: '**', redirectTo: 'pages' }
];
static.routing.module.ts
const routes: Routes = [{
path: '',
component: StaticComponent,
children: [
{
path: '',
redirectTo: 'home',
pathMatch: 'full',
},
{
path: 'home',
component: HomeComponent,
data: { title: 'menu.home' }
},
{
path: 'features',
component: FeaturesComponent,
data: { title: 'menu.features' }
},
{
path: '**',
component: NotFoundComponent,
}
]
}];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class StaticRoutingModule { }
auth.routing.module.ts
export const routes: Routes = [
{
path: '',
component: NbAuthComponent,
children: [
{
path: '',
redirectTo: 'login',
pathMatch: 'full',
},
{
path: 'login',
component: SignInComponent,
},
{
path: 'register',
component: SignUpComponent
}
],
},
];
答案 0 :(得分:0)
儿童:[ { 路径:“, redirectTo:'登录', pathMatch:“已满”, }
这段代码正在重定向到/ login页面,对吗?
答案 1 :(得分:0)
我的问题是我在appModule中导入了authModule,奇怪的是angular并没有触发错误,但是实际上我只是删除了导入模块,并且可以按预期工作。