Active class not being added to NavLinks on active pages on v4.3.1
See original GitHub issueVersion
Upgraded react-router-dom from 4.2.2 → 4.3.1
Node v8.11.2 npm v5.6.0
With the following dependencies:
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"react": "^16.4.0",
"react-dom": "^16.4.0",
"react-router-dom": "^4.3.1",
"webpack": "^4.10.2",
"webpack-cli": "^3.0.1"
Steps to reproduce
After upgrading, the 'active' class is no longer applied to the <NavLink/> for active pages. I’ve tried explicitly adding the activeClassName prop to the component and it still doesn’t add the class the the element.
I haven’t been able to create a minimal verifiable example. Has anyone else seen this? Everything else works perfectly fine, builds like normal, but the active class isn’t added on the updated version.
Expected Behavior
It works as expected with v4.2.2 but not with v4.3.1 (or v4.3.0)
Additional Info
v4.2.2
Props being passed to NavLink:
activeClassName: "active"
ariaCurrent: "true"
children: Array[2]
className: "img-link"
exact: true
to: "/"
JSX and HTML:
<NavLink exact={true} to="/" className="img-link">
↓
<a class="img-link active" aria-current="true" href="#/">
v4.3.1
Props being passed to NavLink:
activeClassName: "active"
aria-current: "page"
children: Array[2]
className: "img-link"
exact: true
to: "/"
JSX and HTML:
<NavLink exact={true} to="/" className="img-link">
↓
<a class="img-link" href="#/">
Issue Analytics
- State:
- Created 5 years ago
- Reactions:25
- Comments:44 (9 by maintainers)

Top Related StackOverflow Question
@dotspencer React Router’s
path-to-regexpdependency isv1.7.0while Express’s isv0.1.7. During installation, thepath-to-regexpdependency for Express is installed before the one for React Router, so you end up with anode_modulesthat looks like this:Your Webpack configuration is set to resolve directly from the root
node_modules, so when you build your project you are building it with the oldpath-to-regexp. The solution, based on this comment is to use a generalizednode_modulesreference in your Webpack config.If anyone else is running into this issue and uses Express + Webpack, can you please verify if this fixes your problem. (cc @dagda1)
I’m also seeing this after upgrading from
4.2.2to4.3.1Workaround: pass a function to the
isActiveprop to do the check manually, eg: