1
- A route configuration object. ` Router ` turns JSX ` <Route/> ` s into
2
- these objects, but you can use them directly if you prefer. All of the
3
- props are the same as ` <Route/> ` props, except those listed here.
1
+ ## Plain Route
4
2
5
- Props
6
- -----
3
+ A plain JavaScript object route definition. ` Router ` turns JSX
4
+ ` <Route/> ` s into these objects, but you can use them directly if you
5
+ prefer. All of the props are the same as ` <Route/> ` props, except
6
+ those listed here.
7
7
8
- ### ` childRoutes `
8
+ ### Props
9
+
10
+ #### ` childRoutes `
9
11
10
12
An array of child routes, same as ` children ` in JSX route configs.
11
13
12
- ### ` getChildRoutes(state , callback) `
14
+ #### ` getChildRoutes(location , callback) `
13
15
14
- Same as ` childRoutes ` but asynchronous and receives the location state .
16
+ Same as ` childRoutes ` but asynchronous and receives the ` location ` .
15
17
Useful for code-splitting and dynamic route matching (given some state
16
18
or session data to return a different set of child routes).
17
19
18
- #### ` callback ` signature
20
+ ##### ` callback ` signature
19
21
20
22
` cb(err, routesArray) `
21
23
22
- #### Example
24
+ ### Examples
23
25
24
26
``` js
25
- var myRoute = {
27
+ let myRoute = {
26
28
path: ' course/:courseId' ,
27
29
childRoutes: [
28
30
announcementsRoute,
@@ -32,9 +34,9 @@ var myRoute = {
32
34
};
33
35
34
36
// async child routes
35
- var myRoute = {
37
+ let myRoute = {
36
38
path: ' course/:courseId' ,
37
- getChildRoutes (state , cb ) {
39
+ getChildRoutes (location , cb ) {
38
40
// do asynchronous stuff to find the child routes
39
41
cb (null , [announcementsRoute, gradesRoute, assignmentsRoute]);
40
42
}
@@ -44,10 +46,10 @@ var myRoute = {
44
46
// can link with some state
45
47
< Link to= " /picture/123" state= {{fromDashboard: true }}/ >
46
48
47
- var myRoute = {
49
+ let myRoute = {
48
50
path: ' picture/:id' ,
49
- getChildRoutes (state , cb ) {
50
- // state gets passed to `getChildRoutes`
51
+ getChildRoutes (location , cb ) {
52
+ let { state } = location
51
53
if (state && state .fromDashboard )
52
54
cb (null , [dashboardPictureRoute])
53
55
else
0 commit comments