Skip to content

Commit

Permalink
[fixed] isActive on nested IndexLink
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-Nikson authored and mjackson committed Oct 7, 2015
1 parent 2732586 commit 24e7b4f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
2 changes: 1 addition & 1 deletion modules/__tests__/IndexLink-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('An <IndexLink>', function () {
<ul>
<li><IndexLink id="overviewLink" to="/website" activeClassName="active">overview</IndexLink></li>
<li><Link id="contactLink" to="/website/contact" activeClassName="active">contact</Link></li>
<li><IndexLink id="productsLink" to="/website/products" activeClassName="active">products</IndexLink></li>
<li><Link id="productsLink" to="/website/products" activeClassName="active">products</Link></li>
<li><Link id="specificProductLink" to="/website/products/15" activeClassName="active">specific product</Link></li>
</ul>
{this.props.children}
Expand Down
10 changes: 2 additions & 8 deletions modules/isActive.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { matchPattern } from './PatternUtils'
import deepEqual from 'deep-equal'
/**
* Returns true if the given pathname matches the active pathname.
*/
function pathnameIsActive(pathname, activePathname) {
return pathname === activePathname || activePathname.indexOf(pathname + '/') === 0
}

function paramsAreActive(paramNames, paramValues, activeParams) {
return paramNames.every(function (paramName, index) {
Expand Down Expand Up @@ -48,7 +42,7 @@ function routeIsActive(pathname, activeRoutes, activeParams, indexOnly) {
return false

if (indexOnly)
return activeRoutes.length > 1 && activeRoutes[activeRoutes.length - 2].indexRoute === route
return activeRoutes.length > 1 && activeRoutes[activeRoutes.length - 1] === route.indexRoute

return true
}
Expand All @@ -75,7 +69,7 @@ function isActive(pathname, query, indexOnly, location, routes, params) {
if (location == null)
return false

if (!pathnameIsActive(pathname, location.pathname) && !routeIsActive(pathname, routes, params, indexOnly))
if (!routeIsActive(pathname, routes, params, indexOnly))
return false

return queryIsActive(query, location.query)
Expand Down

0 comments on commit 24e7b4f

Please sign in to comment.