I created a sample of my project here: stackblitz
I implemented the routing in my Angular application. As a part of that I have written the above Stackblitz.
On that sample there are two components available:
- Appcomponent
- LoginComponet
By default it should go to the LoginComponent whenever we give URL as /home then it should render the AppComponent.
app-routing.module.ts
const appRoutes:Routes=[
{ path: '', component: LoginComponent },
{ path: 'home', component: AppComponent },
{ path: '**', redirectTo: '/not-found', pathMatch: 'full' }
]
App.component.html
<div class="container">
<h2> Hello App component</h2>
</div>
<router-outlet></router-outlet>
But the problem is that by default it is showing the appcomponent and LoginComponet content in the same page.
Can anyone help?
Thanks
<router-outlet>, which in your case is inside of the login component. That means that the content of the login component will be shown in addition to the routed component./loginbut the content is showing theapp.component.html<app-root></app-root>from thelogin.component.htmland if there is in any other component.html exceptapp.component.html. ` <router-outlet></router-outlet>` Should be only in theapp.component.html. Check it works now?<router-outlet></router-outlet>in Login component and kept inapp.component.html. it is showing the login page along with the app.component.html content