03/10/2021, Wed
Organize Routes into Modules
In Angular, to make routing cleaner, routes may be defined inside modules to localize the path definition to where a specific component is associated.
Here, we have the "/useful/" route and nested child route of "/useful/stuff" defined for our "useful component".
//useful.module.ts
import { UsefulComponent } from "./useful.component";
import { NgModule } from "@angular/core";
import { RouterModule } from "@angular/router";
const routes = [
{
path: "",
component: UsefulComponent,
children: [{ path: "stuff", component: UsefulComponent }],
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
})
export class UsefulModule {}