Why a separate routing module
1.Separation of Concerns
2.Maintainability
ng g c employee/create-employee --skipTests=false --flat=true
ng g c employee/list-employees --skipTests=false --flat=true
ng g m app-routing --flat=true --module=app
-
create routing module
-
add routing module into app.module
-
Import routerModule, Routes into app-routing.module
-
create routes in app-routing.module
const appRoutes: Routes = [ {path: 'list', component: }, {path: 'create', component: }, {path: '', redirectTo: '/list', pathMatch: 'full'} ] -
Add navigation menu in root component(app.component.html)
-
Used three directives routerLinkActive, routerLink, router-outlet
-
routerLink asociated directive will be loaded into “router-outlet”
-
If you get ‘router-outlet’ is not a known element, add the “exports: [RouterModule]” into app-routing.module. Make it avilable the RouterModule into root module