Here is an interesting question that I was kind of ignoring, until now. It seems like Angular2 renders the content inside directive tags. But, for router-outlet, it happens to be like a sibling.
My first question is: why? Just out of interest.
I would not worry about it much, but it is now actually causing a problem in my app. I have two nested outlets and for some inexplicable reason, the child one is taking 15px height on the page and does not matter what I do, I can't get rid of it. (see screenshot)
Is what I described really the case or I am simply doing something wrong? Also, I have no idea at this point how to approach this, searched all over, didn't find anything.
Thanks for your help.
UPDATE here is my less file:
@import "../../node_modules/bootstrap-less/bootstrap/bootstrap";
@import "../../node_modules/font-awesome/less/font-awesome";
@icon-font-path: "./bootstrap/fonts/";
@fa-font-path: "./font-awesome/fonts";
@import "rrm.less";
html, body {
height: 100% !important;
}
body {
padding-top: 80px;
}
.load-container {
background: rgba(0, 0, 0, 0.5);
width: 100%;
height: 100%;
.loaing {
position: fixed;
left: 50%;
top: 35%;
z-index: 1000;
height: 31px;
width: 31px;
}
}
.top-navbar {
border-bottom: 1px solid rgba(0, 0, 0, 0.05);
background-color: #FFFFFF;
height: 80px;
&.floating {
.box-shadow(0 1px 3px rgba(0,0,0,.25));
}
.navbar-brand {
height: auto;
img {
height: 60px;
}
}
.navbar-nav > li > a {
font-size: 20px;
padding-top: 15px;
padding-bottom: 15px;
line-height: 50px;
}
}
.rrm-container {
height:100%;
display: table;
width: 100%;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding-left: 0px;
padding-right: 0px;
.rrm-wrapper {
height: 100%;
display: table-row;
.left-menu {
float: none;
display: table-cell;
.box-shadow(0 1px 3px rgba(0,0,0,.25));
ul {
li {
border: none;
background-color: transparent;
}
}
}
.content {
float: none;
display: table-cell;
}
}
}
And here is the box model that FF computes:
The Router outlet is a placeholder that gets filled dynamically by Angular, depending on the current router state. In the previous tutorials, we've used the Router outlet to create basic routing. In this tutorial, we'll see advanced uses of the <router-outlet> component such as named, multiple outlets and auxiliary routing.
You can have multiple outlets in your Angular template: The unnamed outlet is the primary outlet in your app and except for the primary outlet, all the other outlets must have a name.
This route is called an auxiliary route because it's mapped to the secondary outlet. Routes that are mapped to the primary outlet are called primary routes. In this quick post we have seen what a router outlet is in Angular 9, and how to name and create multiple outlets.
This code imports Angular's router module and creates a routes array in which you will keep all your application routes. In Visual Studio Code, open the file src > app > home > home.component.html, delete the existing content, and add following code:
In response to your first question of why place the component template as a sibling of the <router-outlet>
and not inside of it, there are a couple of github threads which shed some light.
https://github.com/angular/angular/issues/8529#issuecomment-217718704 https://github.com/angular/angular/issues/4679
Most relevant:
The original reason for this behavior was to enable animation of elements between views during which time both source and destination components would need to be active
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