我是Angular 2的新手.我想为我的应用程序的每个部分创建独立的模块.例如,我使用默认组件AuthComponent创建了AuthModule,其中包含其子组件(SignIn或SignUp)的路由器插座.所以我想实现以下场景:
但是当我去localhost /我得到重定向到/ auth我想要的东西,但下一次重定向到登录不会出现.
我的代码:app.routing
const routes: Routes = [
{
path: '',
redirectTo: '/auth',
pathMatch: 'full'
}
];
export const appRouting: ModuleWithProviders = RouterModule.forRoot(routes);
Run Code Online (Sandbox Code Playgroud)
auth.routing
const routes: Routes = [
{
path: 'auth',
component: AuthComponent,
children: [
{
path: '',
redirectTo: 'sign-in',
pathMatch: 'full'
},
{
path: 'sign-in',
component: SignInComponent
}
]
},
];
export const authRouting: ModuleWithProviders = RouterModule.forChild(routes);
Run Code Online (Sandbox Code Playgroud)
auth.component.html
<div …Run Code Online (Sandbox Code Playgroud)