File tree Expand file tree Collapse file tree 2 files changed +40
-8
lines changed Expand file tree Collapse file tree 2 files changed +40
-8
lines changed Original file line number Diff line number Diff line change @@ -30,16 +30,20 @@ function createRouter(name, component) {
30
30
} ,
31
31
32
32
render : function ( ) {
33
- // Pass all props except this component to the Router (containing div/body) and the children,
34
- // which are swapped out by the route handler.
35
- var props = assign ( { } , this . props ) ;
36
- delete props . component ;
37
- delete props . children ;
38
- delete props . childProps ;
39
-
40
33
// Render the Route's handler.
41
34
var handler = this . renderRouteHandler ( this . props . childProps ) ;
42
- return React . createElement ( this . props . component , props , handler ) ;
35
+
36
+ if ( ! this . props . component ) {
37
+ return handler ;
38
+ } else {
39
+ // Pass all props except this component to the Router (containing div/body) and the children,
40
+ // which are swapped out by the route handler.
41
+ var props = assign ( { } , this . props ) ;
42
+ delete props . component ;
43
+ delete props . children ;
44
+ delete props . childProps ;
45
+ return React . createElement ( this . props . component , props , handler ) ;
46
+ }
43
47
}
44
48
} ) ;
45
49
}
Original file line number Diff line number Diff line change @@ -87,6 +87,34 @@ describe('react-router-component (on server)', function() {
87
87
} ) ;
88
88
} ) ;
89
89
90
+ describe ( 'Custom Component' , function ( ) {
91
+ class AppSection extends React . Component {
92
+ render ( ) {
93
+ return < Locations className = "App" path = { this . props . path } component = "section" >
94
+ < Location path = "/" handler = { < div > mainpage</ div > } />
95
+ </ Locations > ;
96
+ }
97
+ }
98
+
99
+ class AppNoWrapper extends React . Component {
100
+ render ( ) {
101
+ return < Locations className = "App" path = { this . props . path } component = { null } >
102
+ < Location path = "/" handler = { < div > mainpage</ div > } />
103
+ </ Locations > ;
104
+ }
105
+ }
106
+
107
+ it ( 'renders to <section>' , function ( ) {
108
+ var markup = ReactDOMServer . renderToStaticMarkup ( < AppSection path = "/" /> ) ;
109
+ assert . equal ( markup , '<section class="App"><div>mainpage</div></section>' ) ;
110
+ } ) ;
111
+
112
+ it ( 'removes wrapper with falsy value' , function ( ) {
113
+ var markup = ReactDOMServer . renderToStaticMarkup ( < AppNoWrapper path = "/" /> ) ;
114
+ assert . equal ( markup , '<div>mainpage</div>' ) ;
115
+ } ) ;
116
+ } ) ;
117
+
90
118
describe ( 'contextual router' , function ( ) {
91
119
class rendersSubSlug extends React . Component {
92
120
render ( ) {
You can’t perform that action at this time.
0 commit comments