Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit d267af6

Browse files
committed
refactor(routing): Make use of the latest API for docs & tests
Closes #799
1 parent 260b511 commit d267af6

File tree

3 files changed

+55
-100
lines changed

3 files changed

+55
-100
lines changed

lib/routing/module.dart

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
* * `/recipe/:recipeId/view`
2525
* * `/recipe/:recipeId/edit`
2626
*
27-
*
2827
* Let's try to define those routes in Angular. To get started we need to
2928
* provide an implementation of [RouteInitializerFn] function.
3029
*
@@ -37,29 +36,18 @@
3736
*
3837
* Let's see how we could define our routes using the routing framework:
3938
*
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+
* });
5846
* }
5947
*
6048
* We defined 4 routes and for each route we set views (templates) to be
6149
* 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.
6351
*
6452
* You have to tell Angular where to load views by putting `<ng-view>` tag in
6553
* you template.
@@ -112,41 +100,25 @@
112100
* [RouteEvent.allowLeave].
113101
*
114102
* 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
116104
* easier. For example, notice that we didn't need to manually call
117105
* [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.
120107
*
121108
* ## Hierarchical Routes
122109
*
123110
* The routing framework allows us to define trees of routes. In our recipes
124111
* example we could have defined our routes like this:
125112
*
126113
* 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+
* });
150122
*/
151123
library angular.routing;
152124

lib/routing/ng_view.dart

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,28 @@ part of angular.routing;
99
* [NgViewDirective] can work with [NgViewDirective] to define nested views
1010
* for hierarchical routes. For example:
1111
*
12-
* void initRoutes(Router router, RouteViewFactory view) {
13-
* router.root
14-
* ..addRoute(
15-
* name: 'library',
16-
* path: '/library',
17-
* enter: view('library.html'),
18-
* mount: (Route route) => route
19-
* ..addRoute(
20-
* name: 'all',
21-
* path: '/all',
22-
* enter: view('book_list.html'))
23-
* ..addRoute(
24-
* name: 'book',
25-
* path: '/:bookId',
26-
* mount: (Route route) => route
27-
* ..addRoute(
28-
* name: 'overview',
29-
* path: '/overview',
30-
* defaultRoute: true,
31-
* enter: view('book_overview.html'))
32-
* ..addRoute(
33-
* name: 'read',
34-
* path: '/read',
35-
* enter: view('book_read.html'))));
36-
* }
37-
* }
12+
* void initRoutes(Router router, RouteViewFactory views) {
13+
* views.configure({
14+
* 'library': ngRoute(
15+
* path: '/library',
16+
* view: 'library.html',
17+
* mount: {
18+
* 'all': ngRoute(
19+
* path: '/all',
20+
* view: 'book_list.html'),
21+
* 'book': ngRoute(
22+
* path: '/:bookId',
23+
* mount: {
24+
* 'overview': ngRoute(
25+
* path: '/overview',
26+
* defaultRoute: true,
27+
* view: 'book_overview.html'),
28+
* 'read': ngRoute(
29+
* path: '/read',
30+
* view: 'book_read.html'),
31+
* })
32+
* })
33+
* });
3834
*
3935
* index.html:
4036
*

test/routing/ng_bind_route_spec.dart

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,33 +53,20 @@ main() {
5353
}
5454

5555
class NestedRouteInitializer implements Function {
56-
void call(Router router, RouteViewFactory view) {
57-
router.root
58-
..addRoute(
59-
name: 'library',
60-
path: '/library',
61-
enter: view('library.html'),
62-
mount: (Route route) => route
63-
..addRoute(
64-
name: 'all',
65-
path: '/all',
66-
enter: view('book_list.html'))
67-
..addRoute(
68-
name: 'book',
69-
path: '/:bookId',
70-
mount: (Route route) => route
71-
..addRoute(
72-
name: 'overview',
73-
path: '/overview',
74-
defaultRoute: true,
75-
enter: view('book_overview.html'))
76-
..addRoute(
77-
name: 'read',
78-
path: '/read',
79-
enter: view('book_read.html'))))
80-
..addRoute(
81-
name: 'admin',
82-
path: '/admin',
83-
enter: view('admin.html'));
56+
void call(Router router, RouteViewFactory views) {
57+
views.configure({
58+
'library': ngRoute(
59+
path: '/library',
60+
view: 'library.html',
61+
mount: {
62+
'all': ngRoute(path: '/all', view: 'book_list.html'),
63+
'book': ngRoute(path: '/bookId', mount: {
64+
'overview': ngRoute(path: '/overview', defaultRoute: true,
65+
view: 'book_overview.html'),
66+
'read': ngRoute(path: '/read', view: 'book_read.html'),
67+
'admin': ngRoute(path: '/admin', view: 'admin.html'),
68+
})
69+
})
70+
});
8471
}
8572
}

0 commit comments

Comments
 (0)