I am a newbie in Angular 2. I want to create isolated modules for every part of my app. For example I created the AuthModule
with default component - AuthComponent
which contain a router-outlet
for his child components (SignIn or SignUp). So I want to realise the following scenario:
- When navigate to / - root off app - redirect to /auth
- After redirect to /auth - load AuthComponent with router outlet
- After AppComponent loaded - load default sign-in component via redirecting to /auth/sign-in
But when I going to localhost/ I get redirect to /auth what I want, but the next redirect to sign-in doesn't appear.
My code:
app.routing
const routes: Routes = [
{
path: '',
redirectTo: '/auth',
pathMatch: 'full'
}
];
export const appRouting: ModuleWithProviders = RouterModule.forRoot(routes);
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);
auth.component.html
<div class="container">
<h1>Auth component</h1>
<router-outlet></router-outlet>
</div>
Result:
Environment @angular/cli: 1.0.0-rc.2 node: 7.7.1 os: win32 x64