@@ -66,32 +66,38 @@ Usage
66
66
var Route = require('react-router').Route;
67
67
68
68
React.renderComponent((
69
- <Route handler={App}>
70
- <Route name="about" handler={About}/>
71
- <Route name="users" handler={Users}>
72
- <Route name="user" path="/user/:userId" handler={User}/>
69
+ <Routes>
70
+ <Route handler={App}>
71
+ <Route name="about" handler={About}/>
72
+ <Route name="users" handler={Users}>
73
+ <Route name="user" path="/user/:userId" handler={User}/>
74
+ </Route>
73
75
</Route>
74
- </Route >
76
+ </Routes >
75
77
), document.body);
76
78
```
77
79
78
80
Or if JSX isn't your jam:
79
81
80
82
``` js
81
83
React .renderComponent ((
82
- Route ({handler: App},
83
- Route ({name: " about" , handler: About}),
84
- Route ({name: " users" , handler: Users},
85
- Route ({name: " user" , path: " /user/:userId" , handler: User})
84
+ Routes ({},
85
+ Route ({handler: App},
86
+ Route ({name: " about" , handler: About}),
87
+ Route ({name: " users" , handler: Users},
88
+ Route ({name: " user" , path: " /user/:userId" , handler: User})
89
+ )
86
90
)
87
91
)
88
92
), document .body );
89
93
```
90
94
91
- - Urls will be matched to the deepest route, and then all the routes up
95
+ - URLs will be matched to the deepest route, and then all the routes up
92
96
the hierarchy are activated and their "handlers" (normal React
93
97
components) will be rendered.
94
98
99
+ - Paths are assumed from names unless specified.
100
+
95
101
- Each handler will receive a ` params ` property containing the matched
96
102
parameters form the url, like ` :userId ` .
97
103
@@ -194,24 +200,33 @@ Related Modules
194
200
API
195
201
---
196
202
203
+ ### Routes (component)
204
+
205
+ Configuration component for your router, all ` <Route/> ` s must be
206
+ children of a ` <Routes/> ` . It is the component you provide to
207
+ ` React.renderComponent(routes, el) ` .
208
+
209
+ #### Props
210
+
211
+ ** location** - ` "hash" ` or ` "history" ` , defaults to ` "hash" ` . Configures
212
+ what type of url you want, hash includes ` #/ ` in the url and works
213
+ without a server, if you use ` history ` your server will need to support
214
+ it.
215
+
197
216
### Route (component)
198
217
199
218
Configuration component to declare your application's routes and view hierarchy.
200
219
201
220
#### Props
202
221
203
- ** location** - The method to use for page navigation when initializing the router.
204
- May be either "hash" to use URLs with hashes in them and the ` hashchange ` event or
205
- "history" to use the HTML5 history API. This prop is only ever used on the root
206
- route that is rendered into the page. The default is "hash".
207
-
208
222
** name** - The name of the route, used in the ` Link ` component and the
209
223
router's transition methods.
210
224
211
225
** path** - The path used in the URL, supporting dynamic segments. If
212
- left undefined, the path will be defined by the ` name ` . This path is always
213
- absolute from the URL "root", even if the leading slash is left off. Nested
214
- routes do not inherit the path of their parent.
226
+ left undefined, the path will be defined by the ` name ` , and if there is
227
+ no name, will default to ` / ` . This path is always absolute from the URL
228
+ "root", even if the leading slash is left off. Nested routes do not
229
+ inherit the path of their parent.
215
230
216
231
** handler** - The component to be rendered when the route matches.
217
232
@@ -225,14 +240,17 @@ passing in any additional props as needed.
225
240
#### Examples
226
241
227
242
``` xml
228
- <Route handler ={App}>
229
- <!-- path is automatically assigned to the name since it is omitted -->
230
- <Route name =" about" handler ={About}/>
231
- <Route name =" users" handler ={Users}>
232
- <!-- note the dynamic segment in the path -->
233
- <Route name =" user" handler ={User} path =" /user/:id" />
243
+ <Routes >
244
+ <!-- path defaults to '/' since no name or path provided -->
245
+ <Route handler ={App}>
246
+ <!-- path is automatically assigned to the name since it is omitted -->
247
+ <Route name =" about" handler ={About}/>
248
+ <Route name =" users" handler ={Users}>
249
+ <!-- note the dynamic segment in the path -->
250
+ <Route name =" user" handler ={User} path =" /user/:id" />
251
+ </Route >
234
252
</Route >
235
- </Route >
253
+ </Routes >
236
254
```
237
255
238
256
Or w/o JSX:
0 commit comments