From a780a0b515d87e923fc6c61b165f1fc1258b64bb Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Tue, 20 Jun 2017 01:28:01 -0400 Subject: [PATCH] Create a router just for the sub sections --- nesting.md | 40 ++++++++++++++++++++ router/src/app/about/about-routing.module.ts | 32 ++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 router/src/app/about/about-routing.module.ts diff --git a/nesting.md b/nesting.md index 56abe5b..34856c7 100644 --- a/nesting.md +++ b/nesting.md @@ -5,6 +5,7 @@ 1. Describe nested routes 1. Create components for two sub sections 1. Move the appropriate HTML to each sub section component +1. Create a router just for the sub sections ## Describe nested routes @@ -36,3 +37,42 @@ and `src/app/career/career.component.html`:

Career

Now I'm makin' it raaaiiiiiinnnn!!!

``` + +## Create a router just for the sub sections + +Create `src/app/about/about-routing.module.ts`: + +```javascript +import { NgModule } from '@angular/core'; +import { RouterModule, Routes } from '@angular/router'; +import { AboutComponent } from './about.component'; +import { EarlyLifeComponent } from '../early-life/early-life.component'; +import { CareerComponent } from '../career/career.component'; + +const aboutRoutes: Routes = [ + { + path: 'about', //note the path for the main section + component: AboutComponent, + children: [ //create the sub sections (children) for this route + { + path: 'early-life', + component: EarlyLifeComponent + }, + { + path: 'career', + component: CareerComponent + } + ] + } +]; + +@NgModule({ + imports: [ + RouterModule.forChild(aboutRoutes) + ], + exports: [ + RouterModule + ] +}) +export class AboutRoutingModule { } +``` diff --git a/router/src/app/about/about-routing.module.ts b/router/src/app/about/about-routing.module.ts new file mode 100644 index 0000000..db3ac46 --- /dev/null +++ b/router/src/app/about/about-routing.module.ts @@ -0,0 +1,32 @@ +import { NgModule } from '@angular/core'; +import { RouterModule, Routes } from '@angular/router'; +import { AboutComponent } from './about.component'; +import { EarlyLifeComponent } from '../early-life/early-life.component'; +import { CareerComponent } from '../career/career.component'; + +const aboutRoutes: Routes = [ + { + path: 'about', //note the path for the main section + component: AboutComponent, + children: [ //create the sub sections (children) for this route + { + path: 'early-life', + component: EarlyLifeComponent + }, + { + path: 'career', + component: CareerComponent + } + ] + } +]; + +@NgModule({ + imports: [ + RouterModule.forChild(aboutRoutes) + ], + exports: [ + RouterModule + ] +}) +export class AboutRoutingModule { }