2
2
3
3
block includes
4
4
include ../_util-fns
5
- - var _appRoutingTsVsAppComp = ' app. routing.ts'
5
+ - var _appRoutingTsVsAppComp = ' app- routing.module .ts'
6
6
- var _declsVsDirectives = ' declarations'
7
7
- var _RoutesVsAtRouteConfig = ' Routes'
8
8
- var _RouterModuleVsRouterDirectives = ' RouterModule'
@@ -202,7 +202,7 @@ block router-config-intro
202
202
203
203
Let's define our first route as a route to the heroes component:
204
204
205
- - var _file = _docsFor == ' dart' ? ' app.component.ts' : ' app. routing.ts'
205
+ - var _file = _docsFor == ' dart' ? ' app.component.ts' : ' app- routing.module .ts'
206
206
+ makeExcerpt('app/' + _file + ' (heroes route)' , 'heroes' )
207
207
208
208
- var _are = _docsFor == ' dart' ? ' takes' : ' are'
@@ -224,22 +224,24 @@ block router-config-intro
224
224
225
225
+ ifDocsFor('ts|js' )
226
226
:marked
227
- We'll export a `routing` constant initialized using the `RouterModule.forRoot` method applied to our !{_array} of routes.
228
- This method returns a **configured router module** that we'll add to our root NgModule, `AppModule`.
227
+ We'll create and export an `NgModule` named `AppRoutingModule` that contains our root routing configuration.
228
+ The `AppRoutingModule` class imports the `RouterModule.forRoot` method applied to our !{_array} of routes.
229
+ We'll also add the `RouterModule` to the NgModule `exports`, so modules that add the `AppRoutingModule` to their
230
+ `imports` will have access to the router directives.
229
231
230
- + makeExcerpt('app/app. routing.1.ts (excerpt )' , 'routing-export' )
232
+ + makeExcerpt('app/app- routing.module. 1.ts (app routing )' , 'routing-export' )
231
233
232
234
.l-sub-section
233
235
:marked
234
- We call the `forRoot` method because we're providing a configured router at the _root_ of the application.
236
+ We use the `forRoot` method because we're providing a configured router at the _root_ of the application.
235
237
The `forRoot` method gives us the Router service providers and directives needed for routing.
236
238
237
239
:marked
238
240
### Make the router available
239
241
240
- We've setup initial routes in the `app. routing.ts` file. Now we'll add it to our root NgModule .
242
+ We've setup initial routes in the `app- routing.module. ts` file. Now we'll add it to our `AppModule` .
241
243
242
- Import the `routing` constant from `app. routing.ts` and add it the `imports` !{_array} of `AppModule`.
244
+ Import the `AppRoutingModule` class from `app- routing.module .ts` and add it the `imports` !{_array} of `AppModule`.
243
245
244
246
+ makeExcerpt('app/app.module.ts' , 'routing' )
245
247
@@ -319,12 +321,12 @@ block routerLink
319
321
Import the dashboard component and
320
322
add the following route definition to the `!{_RoutesVsAtRouteConfig}` !{_array} of definitions.
321
323
322
- - var _file = _docsFor == ' dart' ? ' lib/app_component.dart' : ' app/app. routing.ts'
324
+ - var _file = _docsFor == ' dart' ? ' lib/app_component.dart' : ' app/app- routing.module .ts'
323
325
+ makeExcerpt(_file + ' (Dashboard route)' , 'dashboard' )
324
326
325
327
+ ifDocsFor('ts|js' )
326
328
:marked
327
- Also import and add `DashboardComponent` to our root NgModule 's `declarations`.
329
+ Also import and add `DashboardComponent` to our `AppModule` 's `declarations`.
328
330
329
331
+ makeExcerpt('app/app.module.ts' , 'dashboard' )
330
332
@@ -340,7 +342,7 @@ block redirect-vs-use-as-default
340
342
We can use a redirect route to make this happen. Add the following
341
343
to our array of route definitions:
342
344
343
- + makeExcerpt('app/app. routing.ts' ,'redirect' )
345
+ + makeExcerpt('app/app- routing.module .ts' ,'redirect' )
344
346
345
347
.l-sub-section
346
348
:marked
@@ -466,7 +468,7 @@ code-example(format='').
466
468
467
469
Here's the *route definition* we'll use.
468
470
469
- - var _file = _docsFor == ' dart' ? ' app/app.component.ts' : ' app/app. routing.ts'
471
+ - var _file = _docsFor == ' dart' ? ' app/app.component.ts' : ' app/app- routing.module .ts'
470
472
+ makeExcerpt(_file + ' (hero detail)' ,'hero-detail' )
471
473
472
474
:marked
@@ -633,7 +635,7 @@ block extract-id
633
635
token in the parameterized hero detail route definition we added to
634
636
`!{_appRoutingTsVsAppComp}` earlier in the chapter:
635
637
636
- - var _file = _docsFor == ' dart' ? ' app/app.component.ts' : ' app/app. routing.ts'
638
+ - var _file = _docsFor == ' dart' ? ' app/app.component.ts' : ' app/app- routing.module .ts'
637
639
+ makeExcerpt(_file + ' (hero detail)' , 'hero-detail' )
638
640
639
641
:marked
@@ -660,7 +662,7 @@ block extract-id
660
662
661
663
:marked
662
664
Delete the `<h1>` at the top (forgot about it during the `AppComponent`-to-`HeroesComponent` conversion).
663
-
665
+
664
666
Delete the last line of the template with the `<my-hero-detail>` tags.
665
667
666
668
We'll no longer show the full `HeroDetailComponent` here.
@@ -863,7 +865,7 @@ block file-tree-end
863
865
.file app.component.css
864
866
.file app.component.ts
865
867
.file app.module.ts
866
- .file app. routing.ts
868
+ .file app- routing.module .ts
867
869
.file dashboard.component.css
868
870
.file dashboard.component.html
869
871
.file dashboard.component.ts
0 commit comments