0
My application starts with the Logincomponent component:
bootstrap: [LoginComponent]
In my login routing module I set the following routes:
const loginRoutes: Routes = [
{path: 'dash', component: DashboardComponent},
{path: 'registrar', component: RegistrarComponent},
];
@NgModule({
imports:[RouterModule.forRoot(loginRoutes)],
exports: [RouterModule]
})
Dash must be accessed when the user logs in;
In my login.component.html I set an ngIf that will only appear to Dash when the user logs into the system:
<div *ngIf="!usuarioautenticou" class="wrapper">
In this template I set the router-outlet and buttons for browser calls:
<div>
<button type="submit" routerLink="/dash" name="entrar" (click)="fazerLogin()" class="btn btn-success waves-effect" id="login-button">Entrar</button>
<button type="button" routerLink="/registrar" class="btn btn-outline-success waves-effect">Registrar</button>
</div>
<router-outlet></router-outlet>
Everything works perfectly for now. When the application is on localhost:4200 it redirects to the login page. When I click register it changes to the registry component and when I click enter it moves me to the Dash screen.
The problem is that Dash is a fixed component that inside it will have other components, so I tried to put another router-outlet inside Dash:
<router-outlet></router-outlet>
Dashboard.routing.module.ts:
const dashboardRoutes: Routes = [
{ path: '', component: BemvindoComponent },
];
However, the Bemvindocomponent does not appear inside my Dash. It is already as Exports and imported by my Dash route module.
I changed to: {path: 'Dash', Component: Dashboardcomponent, outlet:'primario'}, {path: 'register', Component: Registrarcomponent, outlet:'primario'} and <button type="Submit" routerLink="[{outlets: {primario: ['Dash']" name="enter" (click)="do"btn btn-Success Waves-Effect" id="login-button">Login</button> <button type="button" routerLink="[{outlets: {primary: ['register']" class="btn btn-Outline-Success Waves-Effect">Register</button>
– veroneseComS
You have to put the name attribute in the router-outlet and register the route in the routing module
– mutlei
also put... <router-outlet name="primary"></router-outlet>
– veroneseComS
The routerLink on the button is not between square brackets. It should be
[routerLink]=
– mutlei
using brackets the page does not load... and without brackets does not work
– veroneseComS
On buttons, the attribute value
routerLink
is not closed properly. You have not closed theoutlets
nor the[{
– mutlei
I fixed it. now the page loads, but my Inbox still does not load inside the second router-outlet. The first I set to name "primary", the second left only router-outlet. I need to name this too?
– veroneseComS
Let’s go continue this discussion in chat.
– mutlei