@@ -15,102 +15,30 @@ function Route(name, path, ignoreScrollBehavior, isDefault, isNotFound, onEnter,
15
15
this . handler = handler ;
16
16
}
17
17
18
- Route . prototype . toString = function ( ) {
19
- var string = '<Route' ;
20
-
21
- if ( this . name )
22
- string += ` name="${ this . name } "` ;
23
-
24
- string += ` path="${ this . path } ">` ;
25
-
26
- return string ;
27
- } ;
28
-
29
18
/**
30
19
* Appends the given route to this route's child routes.
31
20
*/
32
- Route . prototype . appendChildRoute = function ( route ) {
21
+ Route . prototype . appendChild = function ( route ) {
33
22
invariant (
34
23
route instanceof Route ,
35
- 'route.appendChildRoute must use a valid Route'
24
+ 'route.appendChild must use a valid Route'
36
25
) ;
37
26
38
27
if ( ! this . childRoutes )
39
28
this . childRoutes = [ ] ;
40
29
41
- if ( route . name ) {
42
- invariant (
43
- this . childRoutes . every ( function ( childRoute ) {
44
- return childRoute . name !== route . name ;
45
- } ) ,
46
- 'Route %s may not have more than one child route named "%s"' ,
47
- this , route . name
48
- ) ;
49
- }
50
-
51
30
this . childRoutes . push ( route ) ;
52
31
} ;
53
32
54
- /**
55
- * Allows looking up a child route using a "." delimited string, e.g.:
56
- *
57
- * route.appendChildRoute(
58
- * Router.createRoute({ name: 'user' }, function () {
59
- * Router.createRoute({ name: 'new' });
60
- * })
61
- * );
62
- *
63
- * var NewUserRoute = route.lookupChildRoute('user.new');
64
- *
65
- * See also Route.findRouteByName.
66
- */
67
- Route . prototype . lookupChildRoute = function ( names ) {
68
- if ( ! this . childRoutes )
69
- return null ;
70
-
71
- return Route . findRouteByName ( this . childRoutes , names ) ;
72
- } ;
73
-
74
- /**
75
- * Searches the given array of routes and returns the route that matches
76
- * the given name. The name should be a . delimited string like "user.new"
77
- * that specifies the names of nested routes. Routes in the hierarchy that
78
- * do not have a name do not need to be specified in the search string.
79
- *
80
- * var routes = [
81
- * Router.createRoute({ name: 'user' }, function () {
82
- * Router.createRoute({ name: 'new' });
83
- * })
84
- * ];
85
- *
86
- * var NewUserRoute = Route.findRouteByName(routes, 'user.new');
87
- */
88
- Route . findRouteByName = function ( routes , names ) {
89
- if ( typeof names === 'string' )
90
- names = names . split ( '.' ) ;
91
-
92
- var route , foundRoute ;
93
- for ( var i = 0 , len = routes . length ; i < len ; ++ i ) {
94
- route = routes [ i ] ;
95
-
96
- if ( route . name === names [ 0 ] ) {
97
- if ( names . length === 1 )
98
- return route ;
99
-
100
- if ( ! route . childRoutes )
101
- return null ;
33
+ Route . prototype . toString = function ( ) {
34
+ var string = '<Route' ;
102
35
103
- return Route . findRouteByName ( route . childRoutes , names . slice ( 1 ) ) ;
104
- } else if ( route . name == null ) {
105
- // Transparently skip over unnamed routes in the tree.
106
- foundRoute = route . lookupChildRoute ( names ) ;
36
+ if ( this . name )
37
+ string += ` name="${ this . name } "` ;
107
38
108
- if ( foundRoute != null )
109
- return foundRoute ;
110
- }
111
- }
39
+ string += ` path="${ this . path } ">` ;
112
40
113
- return null ;
41
+ return string ;
114
42
} ;
115
43
116
44
var _currentRoute ;
@@ -223,7 +151,7 @@ Route.createRoute = function (options, callback) {
223
151
parentRoute . notFoundRoute = route ;
224
152
}
225
153
226
- parentRoute . appendChildRoute ( route ) ;
154
+ parentRoute . appendChild ( route ) ;
227
155
}
228
156
229
157
// Any routes created in the callback
0 commit comments