angular routing issues with child routes

angular routing issues with child routes

I am having problems correctly writing a parent component with child components. When I route to the children it seems to be also re-creating the parent, which results in the html being doubled.

I am having problems correctly writing a parent component with child components. When I route to the children it seems to be also re-creating the parent, which results in the html being doubled.

You can see this in the stackblitz example I have created here.

In the root of my app I have a configuration component:

@Component({
  selector: 'app-configuration',
  template: ` <app-sidebar></app-sidebar>
             <router-outlet></router-outlet>`
   })

This then contains a sidebar component, which has my list of links that I wish to navigate with.

@Component({
  selector: 'app-sidebar',
  template: `<div id="menu">
            <ul *ngFor="let gateway of gateways$ | async">
                <li><a routerLink="configure/{{gateway.toLowerCase()}}"> 
 {{gateway}}</a></li>
            </ul>
          </div>`
   })

export class SidebarComponent implements OnInit {

gateways$:Observable<string[]>; constructor() { } ngOnInit() { this.gateways$ = this.getGateways() } getGateways():Observable<string[]>{ let gateways=["CDS","MCP","CNS"] return of(gateways);
}

The cause of the problem seems to be how I have defined my routes:

const routes: Routes = [
  {
    path:'configure',component: ConfigurationComponent, 
    children:[
        {path:'cds', component: CdsComponent},
        {path:'mcp', component:McpComponent},
        {path:'cns', component:CnsComponent},
    ]
  }

Could someone tell me whether it is possible to do what I am trying to do, the way I am doing it? I was hoping to contain the child components inside the Configuration Component so I could then have sibling components to Configuration to allow me to do other things.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

How to Use Cookies in Angular for Storing user’s Credentials

In this post, I will be explaining about using Cookies in Angular for Storing user’s Credentials

Angular Tutorial - Learn Angular from Scratch

Angular Tutorial - Learn Angular from Scratch: This course is for beginners who are curious on how to get started with Angular. In this course you will learn how to download, install and play around with Angular. We teach you the main components of Angular, so that you can get up and running with it asap. You will learn now to start building applications with Angular.

An Angular Roadmap — The Past, Present, and Future of Angular

✅Interested in being an Angular developer in 2019? ... blog post it's most likely that you've written some code in javaScript in the past.