File tree Expand file tree Collapse file tree 2 files changed +33
-16
lines changed
packages/react-router-dom/modules Expand file tree Collapse file tree 2 files changed +33
-16
lines changed Original file line number Diff line number Diff line change @@ -5,9 +5,10 @@ import invariant from "tiny-invariant";
5
5
import { resolveToLocation , normalizeToLocation } from "./utils/locationUtils" ;
6
6
7
7
// React 15 compat
8
+ const forwardRefShim = C => C ;
8
9
let { forwardRef } = React ;
9
10
if ( typeof forwardRef === "undefined" ) {
10
- forwardRef = C => C ;
11
+ forwardRef = forwardRefShim ;
11
12
}
12
13
13
14
function isModifiedEvent ( event ) {
@@ -70,18 +71,26 @@ const Link = forwardRef(
70
71
) ;
71
72
72
73
const href = location ? history . createHref ( location ) : "" ;
73
-
74
- return React . createElement ( component , {
74
+ const props = {
75
75
...rest ,
76
- ref : forwardedRef || innerRef ,
77
76
href,
78
77
navigate ( ) {
79
78
const location = resolveToLocation ( to , context . location ) ;
80
79
const method = replace ? history . replace : history . push ;
81
80
82
81
method ( location ) ;
83
82
}
84
- } ) ;
83
+ } ;
84
+
85
+ // React 15 compat
86
+ if ( forwardRefShim !== forwardRef ) {
87
+ props . ref = forwardedRef || innerRef ;
88
+ } else {
89
+ // TODO: deprecate
90
+ props . innerRef = innerRef ;
91
+ }
92
+
93
+ return React . createElement ( component , props ) ;
85
94
} }
86
95
</ RouterContext . Consumer >
87
96
) ;
Original file line number Diff line number Diff line change @@ -6,9 +6,10 @@ import Link from "./Link";
6
6
import { resolveToLocation , normalizeToLocation } from "./utils/locationUtils" ;
7
7
8
8
// React 15 compat
9
+ const forwardRefShim = C => C ;
9
10
let { forwardRef } = React ;
10
11
if ( typeof forwardRef === "undefined" ) {
11
- forwardRef = C => C ;
12
+ forwardRef = forwardRefShim ;
12
13
}
13
14
14
15
function joinClassnames ( ...classnames ) {
@@ -67,16 +68,23 @@ const NavLink = forwardRef(
67
68
: classNameProp ;
68
69
const style = isActive ? { ...styleProp , ...activeStyle } : styleProp ;
69
70
70
- return (
71
- < Link
72
- ref = { forwardedRef || innerRef }
73
- aria-current = { ( isActive && ariaCurrent ) || null }
74
- className = { className }
75
- style = { style }
76
- to = { toLocation }
77
- { ...rest }
78
- />
79
- ) ;
71
+ const props = {
72
+ "aria-current" : ( isActive && ariaCurrent ) || null ,
73
+ className,
74
+ style,
75
+ to : toLocation ,
76
+ ...rest
77
+ } ;
78
+
79
+ // React 15 compat
80
+ if ( forwardRefShim !== forwardRef ) {
81
+ props . ref = forwardedRef || innerRef ;
82
+ } else {
83
+ // TODO: deprecate
84
+ props . innerRef = innerRef ;
85
+ }
86
+
87
+ return < Link { ...props } /> ;
80
88
} }
81
89
</ RouterContext . Consumer >
82
90
) ;
You can’t perform that action at this time.
0 commit comments