recently encountered in the development of the problem, the root module in the import of sub-modules, sub-module routing will extend the root module routing.
but root module routing and submodule routing are peer-to-peer.
the following is the root module routing
import { NgModule } from "@angular/core";
import { RouterModule, Routes } from "@angular/router";
import { AuthGuard } from "./common/auth/auth.service";
//
const manage_routes: Routes = [
{
path: "manage",
children: [
{ path: "", redirectTo: "dashboard_conf", pathMatch: "full" },
...
]
}
];
@NgModule({
imports: [ RouterModule.forChild(manage_routes) ],
exports: [ RouterModule ]
})
export class ManageRoutingModule {}
the following is feature module routing
import { NgModule } from "@angular/core";
import { RouterModule, Routes } from "@angular/router";
import { ImageUploadComponent } from "./upload_image.component";
import { ImageConfComponent } from "./image.component";
import { ImageSeriesConfComponent, ImageSeriesConfDetailComponent, ImageSeriesSetComponent } from "./image_series.component";
import { ImageTagConfComponent, ImageTagConfDetailComponent, ImageTagSetComponent } from "./image_tag.component";
import { ImageSeriesCategoryConfComponent, ImageSeriesCategoryConfDetailComponent, ImageSeriesCategoryConfSetDetailComponent} from "./image_series_category.component";
import { ImageRecommendTagConfComponent, ImageRecommendTagConfDetailComponent } from "./image_recommend_tag.component";
//
const image_routes: Routes = [
{ path: "manage/image_upload", component: ImageUploadComponent },
{ path: "manage/image_conf", component: ImageConfComponent },
{
path: "manage/image_series_conf",
children: [
{ path: "", component: ImageSeriesConfComponent },
{ path: "detail/:id", component: ImageSeriesConfDetailComponent },
{ path: "detail/add", component: ImageSeriesConfDetailComponent },
{ path: "set/:id", component: ImageSeriesSetComponent },
]
},
...
];
@NgModule({
imports: [ RouterModule.forChild(image_routes) ],
exports: [ RouterModule ]
})
export class ImageRoutingModule {}
Root module import feature module
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { RouterModule } from "@angular/router";
...
import { ImageModule } from "./image/image.module";
@NgModule({
declarations: [
DashboardConfComponent,
],
imports: [
...
ImageModule, //
ManageRoutingModule, //
],
providers: [
...
]
})
export class ManageModule {
}
final route list
Routes: [
{
"path": "manage/image_series_conf",
"children": [
{
"path": ""
},
{
"path": "detail/:id"
},
{
"path": "detail/add"
},
{
"path": "set/:id"
}
]
},
{
"path": "",
"redirectTo": "manage",
"pathMatch": "full"
}
]
after the two route lists are combined, it is still a level relationship, so how can the feature module be used as a child route of the root module? Can we only write all the routes together?