Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit 9caa8ba

Browse files
committed
reworked isLinkActive to check for nested rotues
1 parent 4950273 commit 9caa8ba

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

functions/isLinkActive.js

+5-17
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,10 @@ export default function isLinkActive(asPath, path) {
1212
return false
1313
}
1414

15-
// TODO: Add functionality to check if link is in the full URL path.
16-
// e.g. /portfolio /portfolio/cambells-soup
17-
18-
return asPath === stripTrailingSlash(path)
19-
}
20-
21-
/**
22-
* Remove the last trailing slash from a URL path.
23-
*
24-
* @author WebDevStudios
25-
* @param {string} str The string to search and remove trailing slash.
26-
* @return {string} The formatted string.
27-
*/
28-
function stripTrailingSlash(str) {
29-
if (str.substr(-1) === '/' && str.length > 1) {
30-
return str.substr(0, str.length - 1)
15+
if (path.length > 1) {
16+
const checkSubStr = new RegExp(path)
17+
return checkSubStr.test(asPath)
3118
}
32-
return str
19+
20+
return path === asPath
3321
}

0 commit comments

Comments
 (0)