I have a main module and some submodules. And I want to point out some non-trivial routing between them.
I would rather define the submodule routes inside the submodule. For instance:
@NgModule({ imports: [ RouterModule.forChild([ { path: 'country', redirectTo: 'country/list' }, { path: 'country/list', component: CountryListComponent }, { path: 'country/create', component: CountryCreateComponent }, ]) ], declarations: [], exports: [ RouterModule, ], }) export class CountryModule {}
I want to import this module with my own internal routing, but I want all its routing to be prefixed.
const appRoutes = [ { path: '', component: HomeComponent }, /*... (basic routes)*/ ]; @NgModule({ imports: [ /*...*/ RouterModule.forRoot(appRoutes), CountryModule, // <- how to make its routing prefixed?? ], declarations: [ /*...*/ AppComponent, ], bootstrap: [ AppComponent ] }) export class AppModule {}
These settings create the following routes: /country
, /country/list
, etc., but I want to make them prefixes like this:
/settings/country
/settings/country/list
/settings/country/create
There are other modules that I want to access through other routing, for example. a CityModule
under /otherstuff/city/create
and / otherstuff / city / list `.
My questions:
- Can I import a module with my own routing and make my routes a prefix?
- In addition: is there a way to make connections between two submodules agnostically their final (prefix) routes?
UPDATE
The accepted answer is the best way to do this: create routes in the module, register them from the outside. This way you can change routes, for example. prefix them (this is what I wanted), you can define guards, redefine or filter them, etc.