Skip to content

Commit 24e7b4f

Browse files
Dr-Niksonmjackson
authored andcommitted
[fixed] isActive on nested IndexLink
1 parent 2732586 commit 24e7b4f

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

modules/__tests__/IndexLink-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('An <IndexLink>', function () {
1818
<ul>
1919
<li><IndexLink id="overviewLink" to="/website" activeClassName="active">overview</IndexLink></li>
2020
<li><Link id="contactLink" to="/website/contact" activeClassName="active">contact</Link></li>
21-
<li><IndexLink id="productsLink" to="/website/products" activeClassName="active">products</IndexLink></li>
21+
<li><Link id="productsLink" to="/website/products" activeClassName="active">products</Link></li>
2222
<li><Link id="specificProductLink" to="/website/products/15" activeClassName="active">specific product</Link></li>
2323
</ul>
2424
{this.props.children}

modules/isActive.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { matchPattern } from './PatternUtils'
22
import deepEqual from 'deep-equal'
3-
/**
4-
* Returns true if the given pathname matches the active pathname.
5-
*/
6-
function pathnameIsActive(pathname, activePathname) {
7-
return pathname === activePathname || activePathname.indexOf(pathname + '/') === 0
8-
}
93

104
function paramsAreActive(paramNames, paramValues, activeParams) {
115
return paramNames.every(function (paramName, index) {
@@ -48,7 +42,7 @@ function routeIsActive(pathname, activeRoutes, activeParams, indexOnly) {
4842
return false
4943

5044
if (indexOnly)
51-
return activeRoutes.length > 1 && activeRoutes[activeRoutes.length - 2].indexRoute === route
45+
return activeRoutes.length > 1 && activeRoutes[activeRoutes.length - 1] === route.indexRoute
5246

5347
return true
5448
}
@@ -75,7 +69,7 @@ function isActive(pathname, query, indexOnly, location, routes, params) {
7569
if (location == null)
7670
return false
7771

78-
if (!pathnameIsActive(pathname, location.pathname) && !routeIsActive(pathname, routes, params, indexOnly))
72+
if (!routeIsActive(pathname, routes, params, indexOnly))
7973
return false
8074

8175
return queryIsActive(query, location.query)

0 commit comments

Comments
 (0)