I am trying to configure my own routing for an Angular application that uses the C8Y Web SDK.
The application is made up of a CoreComponent that is intended to be displayed at all times while the application is running. It contains two custom components: a sidebar component that is anchored to the left side of the window, and a nav-path component anchored to the top of the page that displays a breadcrumb trail of the application being accessed at a given time.
The CoreComponent’s template is as follows
<div class="container">
<app-sidebar></app-sidebar>
<div class="main-content">
<app-nav-path></app-nav-path>
<div class="content">
<router-outlet></router-outlet>
</div>
</div>
</div>
I have defined the routing for my application in my app.module.ts
file:
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { Routes, RouterModule} from "@angular/router";
import {
CoreModule as c8yCoreModule,
BootstrapComponent as c8yBootstrapComponent
} from '@c8y/ngx-components';
import { CoreModule } from './core/core.module';
import { FeaturesModule } from './features/features.module';
import { CoreComponent } from './core/core.component';
const routes: Routes = [
{
path: '',
component: CoreComponent,
children: [
{
path: 'devices',
loadComponent: () => import('../app/features/devices/devices.component').then((c) => c.DevicesComponent)
}
]
},
];
@NgModule({
imports: [
BrowserAnimationsModule,
RouterModule.forRoot(routes, { useHash: true}),
c8yCoreModule.forRoot(),
FeaturesModule,
CoreModule],
bootstrap: [c8yBootstrapComponent],
})
export class AppModule {}
Note: I am hiding both Cumulocity’s
.navigator
and.header
components from the screen.
The main idea is that whatever feature component link is selected on the sidebar, its content will be displayed within the .content
element.
Here’s an example of a link from the sidebar
component:
<li class="nav-item">
<a class="nav-link" routerLink="/devices">
<img src="assets/images/icons/devices-icon.svg" alt="devices" class="icon-devices">
<span class="nav-text">Devices</span>
</a>
</li>
The issue I am having is that when I click on that link, both my sidebar and nav-path components disappear from the screen, and I am only left with the devices feature displaying on screen.
When I consulted the source code using DevTools, I noticed something odd: there were two router-outlet
s being displayed on the page.
Why would there be two router-outlet
’s displayed within my core component? Did I not configure the routing correctly?