You can use this configuration to access parameters from the parent route:
RouterModule.forRoot(appRoutes, {
paramsInheritanceStrategy: 'always'
})
Now you can access :id in base.module. But better name your params more specifically when using this approach.
Another way would be to climb the router state up:
export function extractRoute(route: ActivatedRoute, component: any): ActivatedRoute {
if (route && route.component !== component) {
return extractRoute(route.parent, component);
}
return route;
}
You could use this function with the component that holds the router-outlet corresponding to the router config. For Example
AppComponent->RouterOutlet->
const routes: Routes = [
{
path: 'flight/:id', loadChildren: () => import('./layout/base/base.module').then(m => m.BaseModule)
},
];
The you could acces the id property with:
constructor(private activatedRoute: ActivatedRoute) {}
ngOnInit() {
const id = extractRoute(activatedRoute, AppComponent).snapshot.params.id;
}