|
24 | 24 | * * `/recipe/:recipeId/view`
|
25 | 25 | * * `/recipe/:recipeId/edit`
|
26 | 26 | *
|
27 |
| - * |
28 | 27 | * Let's try to define those routes in Angular. To get started we need to
|
29 | 28 | * provide an implementation of [RouteInitializerFn] function.
|
30 | 29 | *
|
|
37 | 36 | *
|
38 | 37 | * Let's see how we could define our routes using the routing framework:
|
39 | 38 | *
|
40 |
| - * void initRoutes(Router router, RouteViewFactory view) { |
41 |
| - * router.root |
42 |
| - * ..addRoute( |
43 |
| - * name: 'recipes', |
44 |
| - * path: '/recipes', |
45 |
| - * enter: view('recipes.html')) |
46 |
| - * ..addRoute( |
47 |
| - * name: 'addRecipe', |
48 |
| - * path: '/addRecipe', |
49 |
| - * enter: view('addRecipe.html')) |
50 |
| - * ..addRoute( |
51 |
| - * name: 'viewRecipe', |
52 |
| - * path: '/recipe/:recipeId/view', |
53 |
| - * enter: view('viewRecipe.html')) |
54 |
| - * ..addRoute( |
55 |
| - * name: 'editRecipe', |
56 |
| - * path: '/recipe/:recipeId/edit', |
57 |
| - * enter: view('editRecipe.html')); |
| 39 | + * void initRoutes(Router router, RouteViewFactory views) { |
| 40 | + * views.configure({ |
| 41 | + * 'recipes': ngRoute(path: '/recipes', view: 'recipes.html'), |
| 42 | + * 'addRecipe': ngRoute(path: '/addRecipe', view: 'addRecipe.html'), |
| 43 | + * 'viewRecipe': ngRoute(path: '/recipe/:recipeId/view', view: 'viewRecipe.html'), |
| 44 | + * 'editRecipe': ngRoute(path: '/recipe/:recipeId/edit', view: 'editRecipe.html) |
| 45 | + * }); |
58 | 46 | * }
|
59 | 47 | *
|
60 | 48 | * We defined 4 routes and for each route we set views (templates) to be
|
61 | 49 | * displayed when that route is "entered". For example, when the browser URL
|
62 |
| - * is set to `/recipes`, the `recipes.html` will be displayed. |
| 50 | + * is set to `/recipes`, the `recipes.html` template will be displayed. |
63 | 51 | *
|
64 | 52 | * You have to tell Angular where to load views by putting `<ng-view>` tag in
|
65 | 53 | * you template.
|
|
112 | 100 | * [RouteEvent.allowLeave].
|
113 | 101 | *
|
114 | 102 | * Notice that we create a [RouteHandle] for our route. [RouteHandle] are
|
115 |
| - * a convinient wrapper around [Route] that makes unsubscribing route events |
| 103 | + * a convenient wrapper around [Route] that makes unsubscribing route events |
116 | 104 | * easier. For example, notice that we didn't need to manually call
|
117 | 105 | * [StreamSubscription.cancel] for subscription to [Route.onLeave]. Calling
|
118 |
| - * [RouteHandle.discard] unsubscribes all listeneters created for the handle. |
119 |
| - * |
| 106 | + * [RouteHandle.discard] unsubscribes all listeners created for the handle. |
120 | 107 | *
|
121 | 108 | * ## Hierarchical Routes
|
122 | 109 | *
|
123 | 110 | * The routing framework allows us to define trees of routes. In our recipes
|
124 | 111 | * example we could have defined our routes like this:
|
125 | 112 | *
|
126 | 113 | * void initRoutes(Router router, RouteViewFactory view) {
|
127 |
| - * router.root |
128 |
| - * ..addRoute( |
129 |
| - * name: 'recipes', |
130 |
| - * path: '/recipes', |
131 |
| - * enter: view('recipes.html')) |
132 |
| - * ..addRoute( |
133 |
| - * name: 'addRecipe', |
134 |
| - * path: '/addRecipe', |
135 |
| - * enter: view('addRecipe.html')) |
136 |
| - * ..addRoute( |
137 |
| - * name: 'recipe', |
138 |
| - * path: '/recipe/:recipeId', |
139 |
| - * mount: (Route route) => route |
140 |
| - * ..addRoute( |
141 |
| - * name: 'view', |
142 |
| - * path: '/view', |
143 |
| - * enter: view('viewRecipe.html')) |
144 |
| - * ..addRoute( |
145 |
| - * name: 'edit', |
146 |
| - * path: '/edit', |
147 |
| - * enter: view('editRecipe.html'))); |
148 |
| - * } |
149 |
| - * |
| 114 | + * views.configure({ |
| 115 | + * 'recipes': ngRoute(path: '/recipes', view: 'recipes.html'), |
| 116 | + * 'addRecipe': ngRoute(path: '/addRecipe', view: 'addRecipe.html'), |
| 117 | + * 'recipe': ngRoute(path: '/recipe/:recipeId', mount: { |
| 118 | + * 'view': ngRoute(path: '/view', view: 'viewRecipe.html'), |
| 119 | + * 'edit': ngRoute(path: '/edit', view: 'editRecipe.html), |
| 120 | + * }) |
| 121 | + * }); |
150 | 122 | */
|
151 | 123 | library angular.routing;
|
152 | 124 |
|
|
0 commit comments