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

Commit

Permalink
reworked isLinkActive to check for nested rotues
Browse files Browse the repository at this point in the history
  • Loading branch information
johnrobertmcc committed Feb 23, 2022
1 parent 4950273 commit 9caa8ba
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions functions/isLinkActive.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,10 @@ export default function isLinkActive(asPath, path) {
return false
}

// TODO: Add functionality to check if link is in the full URL path.
// e.g. /portfolio /portfolio/cambells-soup

return asPath === stripTrailingSlash(path)
}

/**
* Remove the last trailing slash from a URL path.
*
* @author WebDevStudios
* @param {string} str The string to search and remove trailing slash.
* @return {string} The formatted string.
*/
function stripTrailingSlash(str) {
if (str.substr(-1) === '/' && str.length > 1) {
return str.substr(0, str.length - 1)
if (path.length > 1) {
const checkSubStr = new RegExp(path)
return checkSubStr.test(asPath)
}
return str

return path === asPath
}

0 comments on commit 9caa8ba

Please sign in to comment.