Skip to content

Commit 31b1a79

Browse files
committed
[SQUASH] Actually, it's a lot easier than that to match index route
1 parent 8dd8ceb commit 31b1a79

File tree

1 file changed

+4
-25
lines changed

1 file changed

+4
-25
lines changed

modules/isActive.js

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,33 +66,12 @@ function getMatchingRoute(pathname, activeRoutes, activeParams) {
6666
* Returns true if the given pathname matches the active routes
6767
* and params.
6868
*/
69-
function routeIsActive(pathname, activeRoutes, activeParams, indexOnly) {
70-
let route = getMatchingRoute(pathname, activeRoutes, activeParams)
71-
72-
if (route == null) {
73-
return false
74-
}
75-
69+
function routeIsActive(pathname, location, routes, params, indexOnly) {
7670
if (indexOnly) {
77-
if (activeRoutes.length < 2) {
78-
return false
79-
}
80-
81-
const lastRoute = activeRoutes[activeRoutes.length - 1]
82-
if (route.indexRoute) {
83-
return lastRoute === route.indexRoute
84-
}
85-
86-
// TODO: Should we also return true if lastRoute is route?
87-
88-
// In case the index route was configured via getIndexRoute.
89-
return (
90-
activeRoutes[activeRoutes.length - 2] === route &&
91-
!lastRoute.path // Pathless route must have been the index route.
92-
)
71+
return location.pathname.replace(/\/*$/) === pathname.replace(/\/*$/)
9372
}
9473

95-
return true
74+
return getMatchingRoute(pathname, routes, params) != null
9675
}
9776

9877
/**
@@ -117,7 +96,7 @@ function isActive(pathname, query, indexOnly, location, routes, params) {
11796
if (location == null)
11897
return false
11998

120-
if (!routeIsActive(pathname, routes, params, indexOnly))
99+
if (!routeIsActive(pathname, location, routes, params, indexOnly))
121100
return false
122101

123102
return queryIsActive(query, location.query)

0 commit comments

Comments
 (0)