I have some trouble with child route-outlet. I have dashboard module and child modules as profile, staff etc. But profile component loads not only on link localhost:4200/dashboard/profile, but just localhost:4200/profile too. Seems like child component loads to root route-outlet
here is the example only with login (but it the same project and configuration also the same), works as idr-frontend.staging.myappworx.com/auth/login and idr-frontend.staging.myappworx.com/login
1. App.module
import {routing} from './app.routing';
import {DashboardModule} from './dashboard/dashboard.module';
import {AppComponent} from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
routing,
DashboardModule
]
})
export class AppModule {}
2. App.routing.ts
import {Routes, RouterModule} from '@angular/router';
import {DashboardComponent} from './dashboard/dashboard.component';
import {LoginRedirect} from './auth/services/login-redirect.service';
import {EnsureAuthenticated} from './auth/services/ensure-authenticated.service';
const appRoutes: Routes = [
{
path: 'dashboard',
component: DashboardComponent,
canActivate: [EnsureAuthenticated],
loadChildren: './dashboard/dashboard.module#DashboardModule',
},
{
path: '**',
redirectTo: 'dashboard',
canActivate: [EnsureAuthenticated]
}
];
export const routing = RouterModule.forRoot(appRoutes);
3. app.component.html
<router-outlet></router-outlet>
4. dashboard.module.ts
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {DashboardComponent} from './dashboard.component';
import {dashboardRouting} from './dashboard.routing';
import {ProfileModule} from '../profile/profile.module';
import { StaffModule } from '../staff/staff.module';
@NgModule({
imports: [
CommonModule,
FormsModule,
dashboardRouting,
ProfileModule,
StaffModule
],
declarations: [
DashboardComponent
],
providers: [
],
exports: []
})
export class DashboardModule {}
5. dashboard.routing.ts
import {Routes, RouterModule} from '@angular/router';
import {ProfileComponent} from '../profile/profile.component';
import {EnsureAuthenticated} from '../auth/services/ensure-authenticated.service';
import { StaffComponent } from '../staff/staff.component';
const dashboardRoutes: Routes = [
{
path: 'profile',
component: ProfileComponent,
canActivate: [EnsureAuthenticated]
},
{
path: 'staff',
component: StaffComponent,
canActivate: [EnsureAuthenticated]
}
];
export const dashboardRouting = RouterModule.forChild(dashboardRoutes);
6. dashboard.component.html
<div class="contentWrap">
<header class="header">
<div class="currentTime">
{{currentTime}}
</div>
<div class="status"></div>
</header>
<router-outlet></router-outlet>
</div>