I have a main router-outlet, which is used to display a login screen (/login) and the main content screen(which is shown after login) (/main
So if I get the question right you want to have login screen initially and after the user logs in, you want him to see /main where navigation is shown. Both login screen and main application should have a different layout.
We have a similar case and using LayoutComponent. Here's simplified example.
// This is main component that get's bootstrapped that has 'top-level' router.
@Component({selector: 'app', template: ' '})
class AppComponent {}
// main router config
// Here AuthModule has router with login and logout configured and LoginGuard
// redirect the user to /auth/login when she is not authenticated.
// We're using lazy-loading but you can use direct component instead
export const APP_ROUTES: Routes = [
{path: '', redirectTo: 'main', pathMatch: 'full'},
{path: 'auth', loadChildren: '../modules/+auth/auth.module#AuthModule'},
{
path: '',
component: LayoutComponent,
canActivate: [LoginGuard],
children: [
{path: 'main', loadChildren: '../modules/+main/main.module#MainModule'}
]
}
];
// AuthModule/LoginComponent has own template and it will be rendered
// into 'top-level' router-outlet.
// LayoutComponent
// Here you define your main application layout that can include navigation
// and anything else that are global to the app. It has another router-outlet
// that get rendered when the layout is accessible (which in this case when the user is authenticated).
@Component({
selector: 'app-layout',
template: `
`
})
export class LayoutComponent {}
// Auth/LoginComponent can have its own template that will have different layout from the main application
So the flow would be like so:
Hope that helps.
EDIT: Updated sickelap/ng-starter repository with example app that has: