File tree 3 files changed +36
-29
lines changed
3 files changed +36
-29
lines changed Original file line number Diff line number Diff line change 14
14
}
15
15
},
16
16
"umd/react-router-dom.js" : {
17
- "bundled" : 162079 ,
18
- "minified" : 57806 ,
19
- "gzipped" : 16662
17
+ "bundled" : 162277 ,
18
+ "minified" : 57870 ,
19
+ "gzipped" : 16689
20
20
},
21
21
"umd/react-router-dom.min.js" : {
22
- "bundled" : 97956 ,
23
- "minified" : 34459 ,
24
- "gzipped" : 10224
22
+ "bundled" : 98089 ,
23
+ "minified" : 34473 ,
24
+ "gzipped" : 10230
25
25
}
26
26
}
Original file line number Diff line number Diff line change 1
1
{
2
2
"esm/react-router.js" : {
3
- "bundled" : 23136 ,
4
- "minified" : 13099 ,
5
- "gzipped" : 3654 ,
3
+ "bundled" : 23391 ,
4
+ "minified" : 13245 ,
5
+ "gzipped" : 3676 ,
6
6
"treeshaked" : {
7
7
"rollup" : {
8
- "code" : 2267 ,
8
+ "code" : 2209 ,
9
9
"import_statements" : 465
10
10
},
11
11
"webpack" : {
12
- "code" : 3630
12
+ "code" : 3572
13
13
}
14
14
}
15
15
},
16
16
"umd/react-router.js" : {
17
- "bundled" : 102232 ,
18
- "minified" : 36232 ,
19
- "gzipped" : 11519
17
+ "bundled" : 102432 ,
18
+ "minified" : 36295 ,
19
+ "gzipped" : 11538
20
20
},
21
21
"umd/react-router.min.js" : {
22
- "bundled" : 63839 ,
23
- "minified" : 22264 ,
24
- "gzipped" : 7893
22
+ "bundled" : 63974 ,
23
+ "minified" : 22277 ,
24
+ "gzipped" : 7899
25
25
}
26
26
}
Original file line number Diff line number Diff line change 1
1
import React from "react" ;
2
2
import PropTypes from "prop-types" ;
3
+ import RouterContext from "./RouterContext" ;
3
4
import hoistStatics from "hoist-non-react-statics" ;
4
-
5
- import Route from "./Route" ;
5
+ import invariant from "tiny-invariant" ;
6
6
7
7
/**
8
8
* A public higher-order component to access the imperative API
9
9
*/
10
10
function withRouter ( Component ) {
11
+ const displayName = `withRouter(${ Component . displayName || Component . name } )` ;
11
12
const C = props => {
12
13
const { wrappedComponentRef, ...remainingProps } = props ;
13
14
14
15
return (
15
- < Route
16
- children = { routeComponentProps => (
17
- < Component
18
- { ...remainingProps }
19
- { ...routeComponentProps }
20
- ref = { wrappedComponentRef }
21
- />
22
- ) }
23
- />
16
+ < RouterContext . Consumer >
17
+ { context => {
18
+ invariant (
19
+ context ,
20
+ `You should not use <${ displayName } /> outside a <Router>`
21
+ ) ;
22
+ return (
23
+ < Component
24
+ { ...remainingProps }
25
+ { ...context }
26
+ ref = { wrappedComponentRef }
27
+ />
28
+ ) ;
29
+ } }
30
+ </ RouterContext . Consumer >
24
31
) ;
25
32
} ;
26
33
27
- C . displayName = `withRouter( ${ Component . displayName || Component . name } )` ;
34
+ C . displayName = displayName ;
28
35
C . WrappedComponent = Component ;
29
36
30
37
if ( __DEV__ ) {
You can’t perform that action at this time.
0 commit comments