@@ -148,8 +148,8 @@ var App = React.createClass({
148
148
var routes = (
149
149
< Routes location= " history" >
150
150
< Route name= " app" path= " /" handler= {App}>
151
- < Route name= " inbox" path = " /inbox " handler= {Inbox}/ >
152
- < Route name= " calendar" path = " /calendar " handler= {Calendar}/ >
151
+ < Route name= " inbox" handler= {Inbox}/ >
152
+ < Route name= " calendar" handler= {Calendar}/ >
153
153
< DefaultRoute handler= {Dashboard}/ >
154
154
< / Route>
155
155
< / Routes>
@@ -228,14 +228,14 @@ var Inbox = React.createClass({
228
228
229
229
var routes = (
230
230
< Routes location= " history" >
231
- < Route path = " / " handler= {App}>
231
+ < Route handler= {App}>
232
232
233
- < Route name= " inbox" path = " /inbox " handler= {Inbox}>
234
- < Route name= " message" path= " /inbox/ :messageId" handler= {Message}/ >
233
+ < Route name= " inbox" handler= {Inbox}>
234
+ < Route name= " message" path= " :messageId" handler= {Message}/ >
235
235
< DefaultRoute handler= {InboxStats}/ >
236
236
< / Route>
237
237
238
- < Route name= " calendar" path = " /calendar " handler= {Calendar}/ >
238
+ < Route name= " calendar" handler= {Calendar}/ >
239
239
< DefaultRoute handler= {Dashboard}/ >
240
240
241
241
< / Route>
@@ -251,13 +251,6 @@ var routes = (
251
251
Nesting a new level of UI does not increase the complexity of your code.
252
252
You simply nest some routes and render them with ` activeRouteHandler ` .
253
253
254
- ** Note** : the paths are not inherited from parent to child. This gives
255
- you the flexibility to have any url you need. Were the paths to be
256
- inherited, you'd be forced to couple your urls to your route hierarchy.
257
- For example, we may want ` /inbox ` and ` /messages/123 ` instead of ` /inbox `
258
- and ` /inbox/123 ` . We can just change the path on the ` message ` route and
259
- still get view nesting even though the urls are not nested.
260
-
261
254
Dynamic Segments
262
255
----------------
263
256
@@ -268,7 +261,7 @@ route handler on `this.props.params`.
268
261
Remember our message route looks like this:
269
262
270
263
``` xml
271
- <Route name =" message" path =" /inbox/ :messageId" handler ={Message}/>
264
+ <Route name =" message" path =" :messageId" handler ={Message}/>
272
265
```
273
266
274
267
Lets look at accessing the ` messageId ` in ` Message ` .
@@ -305,15 +298,66 @@ If you'd rather be lazy, you can use the `addHandlerKey` option and set
305
298
it to ` true ` on your route to opt-out of the performance. See also
306
299
[ Route] [ Route ] .
307
300
308
- Links
309
- -----
301
+ Scrolling
302
+ ---------
303
+
304
+ By default, the router will manage the scroll position between route
305
+ transitions. When a user clicks "back" or "forward", it will restore
306
+ their scroll position. If they visit a new route, it will automatically
307
+ scroll the window to the top. You can opt out of this with the
308
+ ` preserverScrollPosition ` option on [ Routes] [ Routes ] or [ Route] [ Route ] .
309
+
310
+ Bells and Whistles
311
+ ------------------
312
+
313
+ ### ` <Link/> `
310
314
311
315
The ` <Link/> ` component allows you to conveniently navigate users around
312
316
the application with accessible anchor tags that don't break normal link
313
317
functionality like control/command clicking to open in a new tab. Also,
314
318
when the route a link references is active, you get the ` active ` css
315
319
class to easily style your UI.
316
320
321
+ ### ` <NotFoundRoute/> `
322
+
323
+ At any level of your UI nesting, you can render a handler if the url
324
+ beyond what was matched isn't recognized.
325
+
326
+ ``` xml
327
+ <Routes location =" history" >
328
+ <Route path =" /" handler ={App}>
329
+ <Route name =" inbox" path =" /inbox" handler ={Inbox}>
330
+ <!--
331
+ will render inside the `Inbox` UI for any paths not recognized
332
+ after the parent route's path `/inbox/*`
333
+ -->
334
+ <NotFoundRoute handler ={InboxNotFound}
335
+ <Route name =" message" path =" /inbox/:messageId" handler ={Message}/>
336
+ <DefaultRoute handler ={InboxStats}/>
337
+ </Route >
338
+ <Route name =" calendar" path =" /calendar" handler ={Calendar}/>
339
+ <DefaultRoute handler ={Dashboard}/>
340
+ </Route >
341
+ <!-- will catch any route that isn't recognized at all -->
342
+ <NotFoundRoute handler ={NotFound}
343
+ </Routes>
344
+ ```
345
+
346
+ ### ` <Redirect/> `
347
+
348
+ URLs in an app change, so we made it easy to not break the old ones.
349
+
350
+ ``` xml
351
+ <Route name =" message" path =" /inbox/:messageId" handler ={Message} />
352
+ <Redirect path =" /messages/:messageId" to =" message" />
353
+ ```
354
+
355
+ Path Matching
356
+ -------------
357
+
358
+ There's a lot more to be said about path matching, check out the [ Path
359
+ Matching Guide] [ path-matching ] .
360
+
317
361
API Documentation
318
362
-----------------
319
363
@@ -323,5 +367,7 @@ redirecting transitions, query parameters and more.
323
367
324
368
[ AsyncState ] :../api/mixins/AsyncState.md
325
369
[ Route ] :../api/components/Route.md
370
+ [ Routes ] :../api/components/Routes.md
326
371
[ API ] :../api/
372
+ [ path-matching ] :./path-matching.md
327
373
0 commit comments