Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit b156d9b

Browse files
docs(toh): Updated routing tutorial to use routing module
1 parent 6def950 commit b156d9b

File tree

6 files changed

+78
-23
lines changed

6 files changed

+78
-23
lines changed

public/docs/_examples/toh-5/ts/app/app.routing.1.ts renamed to public/docs/_examples/toh-5/ts/app/app-routing.module.1.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// #docregion , heroes, routing
2-
import { ModuleWithProviders } from '@angular/core';
2+
import { NgModule } from '@angular/core';
33
import { Routes, RouterModule } from '@angular/router';
44

55
import { HeroesComponent } from './heroes.component';
@@ -13,5 +13,13 @@ const appRoutes: Routes = [
1313
// #enddocregion heroes, routing
1414

1515
// #docregion routing-export
16-
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
16+
@NgModule({
17+
imports: [
18+
RouterModule.forRoot(appRoutes)
19+
],
20+
exports: [
21+
RouterModule
22+
]
23+
})
24+
export class AppRoutingModule {}
1725
// #enddocregion routing-export

public/docs/_examples/toh-5/ts/app/app.routing.ts renamed to public/docs/_examples/toh-5/ts/app/app-routing.module.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #docplaster
22
// #docregion , heroes
3-
import { ModuleWithProviders } from '@angular/core';
3+
import { NgModule } from '@angular/core';
44
import { Routes, RouterModule } from '@angular/router';
55

66
// #enddocregion heroes
@@ -40,4 +40,12 @@ const appRoutes: Routes = [
4040
];
4141
// #enddocregion heroes
4242

43-
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
43+
@NgModule({
44+
imports: [
45+
RouterModule.forRoot(appRoutes)
46+
],
47+
exports: [
48+
RouterModule
49+
]
50+
})
51+
export class AppRoutingModule {}

public/docs/_examples/toh-5/ts/app/app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import { HeroDetailComponent } from './hero-detail.component';
1010
import { HeroesComponent } from './heroes.component';
1111
import { HeroService } from './hero.service';
1212
// #docregion routing
13-
import { routing } from './app.routing';
13+
import { AppRoutingModule } from './app-routing.module';
1414
// #docregion routing
1515

1616
@NgModule({
1717
imports: [
1818
BrowserModule,
1919
FormsModule,
20-
routing
20+
AppRoutingModule
2121
],
2222
// #enddocregion routing
2323
// #docregion dashboard, hero-detail
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// #docregion
2+
import { NgModule } from '@angular/core';
3+
import { Routes, RouterModule } from '@angular/router';
4+
5+
import { DashboardComponent } from './dashboard.component';
6+
import { HeroesComponent } from './heroes.component';
7+
import { HeroDetailComponent } from './hero-detail.component';
8+
9+
const appRoutes: Routes = [
10+
{
11+
path: '',
12+
redirectTo: '/dashboard',
13+
pathMatch: 'full'
14+
},
15+
{
16+
path: 'dashboard',
17+
component: DashboardComponent
18+
},
19+
{
20+
path: 'detail/:id',
21+
component: HeroDetailComponent
22+
},
23+
{
24+
path: 'heroes',
25+
component: HeroesComponent
26+
}
27+
];
28+
29+
@NgModule({
30+
imports: [
31+
RouterModule.forRoot(appRoutes)
32+
],
33+
exports: [
34+
RouterModule
35+
]
36+
})
37+
export class AppRoutingModule {}

public/docs/_examples/toh-6/ts/app/app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { HeroService } from './hero.service';
2424
// #enddocregion v1, v2
2525
import { HeroSearchComponent } from './hero-search.component';
2626
// #docregion v1, v2
27-
import { routing } from './app.routing';
27+
import { AppRoutingModule } from './app-routing.module';
2828

2929
@NgModule({
3030
imports: [
@@ -36,7 +36,7 @@ import { routing } from './app.routing';
3636
InMemoryWebApiModule.forRoot(InMemoryDataService),
3737
// #enddocregion in-mem-web-api
3838
// #docregion v1
39-
routing
39+
AppRoutingModule
4040
],
4141
// #docregion search
4242
declarations: [

public/docs/ts/latest/tutorial/toh-pt5.jade

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
block includes
44
include ../_util-fns
5-
- var _appRoutingTsVsAppComp = 'app.routing.ts'
5+
- var _appRoutingTsVsAppComp = 'app-routing.module.ts'
66
- var _declsVsDirectives = 'declarations'
77
- var _RoutesVsAtRouteConfig = 'Routes'
88
- var _RouterModuleVsRouterDirectives = 'RouterModule'
@@ -202,7 +202,7 @@ block router-config-intro
202202

203203
Let's define our first route as a route to the heroes component:
204204

205-
- var _file = _docsFor == 'dart' ? 'app.component.ts' : 'app.routing.ts'
205+
- var _file = _docsFor == 'dart' ? 'app.component.ts' : 'app-routing.module.ts'
206206
+makeExcerpt('app/' + _file + ' (heroes route)', 'heroes')
207207

208208
- var _are = _docsFor == 'dart' ? 'takes' : 'are'
@@ -224,22 +224,24 @@ block router-config-intro
224224

225225
+ifDocsFor('ts|js')
226226
: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.
229231

230-
+makeExcerpt('app/app.routing.1.ts (excerpt)', 'routing-export')
232+
+makeExcerpt('app/app-routing.module.1.ts (app routing)', 'routing-export')
231233

232234
.l-sub-section
233235
: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.
235237
The `forRoot` method gives us the Router service providers and directives needed for routing.
236238

237239
:marked
238240
### Make the router available
239241

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`.
241243

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`.
243245

244246
+makeExcerpt('app/app.module.ts', 'routing')
245247

@@ -319,12 +321,12 @@ block routerLink
319321
Import the dashboard component and
320322
add the following route definition to the `!{_RoutesVsAtRouteConfig}` !{_array} of definitions.
321323

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'
323325
+makeExcerpt(_file + ' (Dashboard route)', 'dashboard')
324326

325327
+ifDocsFor('ts|js')
326328
:marked
327-
Also import and add `DashboardComponent` to our root NgModule's `declarations`.
329+
Also import and add `DashboardComponent` to our `AppModule`'s `declarations`.
328330

329331
+makeExcerpt('app/app.module.ts', 'dashboard')
330332

@@ -340,7 +342,7 @@ block redirect-vs-use-as-default
340342
We can use a redirect route to make this happen. Add the following
341343
to our array of route definitions:
342344

343-
+makeExcerpt('app/app.routing.ts','redirect')
345+
+makeExcerpt('app/app-routing.module.ts','redirect')
344346

345347
.l-sub-section
346348
:marked
@@ -466,7 +468,7 @@ code-example(format='').
466468

467469
Here's the *route definition* we'll use.
468470

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'
470472
+makeExcerpt(_file + ' (hero detail)','hero-detail')
471473

472474
:marked
@@ -633,7 +635,7 @@ block extract-id
633635
token in the parameterized hero detail route definition we added to
634636
`!{_appRoutingTsVsAppComp}` earlier in the chapter:
635637

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'
637639
+makeExcerpt(_file + ' (hero detail)', 'hero-detail')
638640

639641
:marked
@@ -660,7 +662,7 @@ block extract-id
660662

661663
:marked
662664
Delete the `<h1>` at the top (forgot about it during the `AppComponent`-to-`HeroesComponent` conversion).
663-
665+
664666
Delete the last line of the template with the `<my-hero-detail>` tags.
665667

666668
We'll no longer show the full `HeroDetailComponent` here.
@@ -863,7 +865,7 @@ block file-tree-end
863865
.file app.component.css
864866
.file app.component.ts
865867
.file app.module.ts
866-
.file app.routing.ts
868+
.file app-routing.module.ts
867869
.file dashboard.component.css
868870
.file dashboard.component.html
869871
.file dashboard.component.ts

0 commit comments

Comments
 (0)