File tree Expand file tree Collapse file tree 2 files changed +48
-2
lines changed Expand file tree Collapse file tree 2 files changed +48
-2
lines changed Original file line number Diff line number Diff line change 1
1
var React = require ( 'react' ) ;
2
2
var Configuration = require ( '../Configuration' ) ;
3
3
var PropTypes = require ( '../PropTypes' ) ;
4
-
4
+ var RouteHandler = require ( './RouteHandler' ) ;
5
5
/**
6
6
* <Route> components specify components that are rendered to the page when the
7
7
* URL matches a given pattern.
@@ -39,6 +39,8 @@ var PropTypes = require('../PropTypes');
39
39
* );
40
40
* }
41
41
* });
42
+ *
43
+ * If no handler is provided for the route, it will render a matched child route.
42
44
*/
43
45
var Route = React . createClass ( {
44
46
@@ -49,8 +51,14 @@ var Route = React.createClass({
49
51
propTypes : {
50
52
name : PropTypes . string ,
51
53
path : PropTypes . string ,
52
- handler : PropTypes . func . isRequired ,
54
+ handler : PropTypes . func ,
53
55
ignoreScrollBehavior : PropTypes . bool
56
+ } ,
57
+
58
+ getDefaultProps : function ( ) {
59
+ return {
60
+ handler : RouteHandler
61
+ } ;
54
62
}
55
63
56
64
} ) ;
Original file line number Diff line number Diff line change
1
+ var expect = require ( 'expect' ) ;
2
+ var React = require ( 'react' ) ;
3
+ var Router = require ( '../../index' ) ;
4
+ var DefaultRoute = require ( '../DefaultRoute' ) ;
5
+ var Route = require ( '../Route' ) ;
6
+ var { Foo, Bar } = require ( '../../utils/TestHandlers' ) ;
7
+
8
+ describe ( 'Route' , function ( ) {
9
+
10
+ it ( 'renders default child route if path match but no handler provided' , function ( ) {
11
+ var routes = (
12
+ < Route path = '/' >
13
+ < Route path = '/bar' handler = { Bar } />
14
+ < DefaultRoute handler = { Foo } />
15
+ </ Route >
16
+ ) ;
17
+
18
+ Router . run ( routes , '/' , function ( App ) {
19
+ var html = React . renderToString ( < App /> ) ;
20
+ expect ( html ) . toMatch ( / F o o / ) ;
21
+ } ) ;
22
+ } ) ;
23
+
24
+ it ( 'renders matched child route if no handler provided' , function ( ) {
25
+ var routes = (
26
+ < Route path = '/' >
27
+ < Route path = '/bar' handler = { Bar } />
28
+ < DefaultRoute handler = { Foo } />
29
+ </ Route >
30
+ ) ;
31
+
32
+ Router . run ( routes , '/bar' , function ( App ) {
33
+ var html = React . renderToString ( < App /> ) ;
34
+ expect ( html ) . toMatch ( / B a r / ) ;
35
+ } ) ;
36
+ } ) ;
37
+
38
+ } ) ;
You can’t perform that action at this time.
0 commit comments