I am working on a angular 4 application and I want load login.page.ts outside of the router-outlet
this is my home.component.html file
<div class="container">
<top-nav-bar></top-nav-bar>
<lett-nav-bar></lett-nav-bar>
<router-outlet></router-outlet>
</div>
routes configs
const MAINMENU_ROUTES: Routes = [
{ path: 'login', component: LoginComponent },
{ path: '', redirectTo: 'home', pathMatch: 'full'},
{ path: 'home', component: HomeComponent, canActivate: [AuthGuard]}
];
with this, I can load login page inside the router but I want to load login page in full screen before coming to the router-outlet.
The router-outlet is a directive that's available from the @angular/router package and is used by the router to mark where in a template, a matched component should be inserted. Thanks to the router outlet, your app will have multiple views/pages and the app template acts like a shell of your application.
forRoot creates a module that contains all the directives, the given routes, and the router service itself. forChild creates a module that contains all the directives and the given routes, but does not include the router service. It registers the routers and uses the router service created at the root level.
You cannot route to a page without a router outlet. Based on what you are describing, it sounds like you need another router outlet at a higher level, say in an App Component. Something like this:
<div class="container">
<router-outlet></router-outlet>
</div>
Then you can route the login page and the home component into this router outlet.
Your route configuration would then look something like this:
{ path: 'login', component: LoginComponent },
{ path: 'home', component: HomeComponent, canActivate: [AuthGuard],
children: [
{ path: 'child1', component: Child1Component },
{ path: 'child2', component: Child2Component }
]
}
The login and home routes would then appear in the App Component's router outlet, so the login page would be shown full screen with no nav bars. And the child1 and child2 routes would appear in the Home Component's router outlet.
DeborahK
answer is the recommended solution, but there is a way to avoid having another router outlet by using a query parameter that is recognized in App Component which can react and have some elements (header, footer) disappear.
<app-nav-menu [hidden]="hasFullView"></app-nav-menu>
<div class="{{!hasFullView ? 'body-container' : ''}}">
<router-outlet></router-outlet>
</div>
<app-footer [hidden]="hasFullView"></app-footer>
hasFullView = false;
private setHasFullView() {
this.activatedRoute.queryParams.subscribe(params => {
this.hasFullView = params["hasFullView"] || false;
});
}
ngOnInit() {
this.setHasFullView();
}
showPrintView() {
const url = `module/user-edit-printout/${userId}?hasFullView=true`;
window.open(url);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With