Skip to content

Commit 0abe366

Browse files
committed
fix: _setActiveLink() doesn't work if is # in url
1 parent 61050f7 commit 0abe366

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

js/src/sidebar.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,21 +441,31 @@ class Sidebar {
441441
_setActiveLink() {
442442
// eslint-disable-next-line unicorn/prefer-spread
443443
Array.from(this._element.querySelectorAll(SELECTOR_NAV_LINK)).forEach(element => {
444-
let currentUrl
444+
let currentUrl = String(window.location)
445445

446-
const urlHasParams = /\\?.*=/
447-
const urlHasQueryString = /\\?./
446+
const urlHasParams = /\?.*=/
447+
const urlHasQueryString = /\?./
448448
const urlHasHash = /#./
449449

450-
if (urlHasParams.test(String(window.location)) || urlHasQueryString.test(String(window.location))) {
451-
currentUrl = String(window.location).split('?')[0]
452-
} else if (urlHasHash.test(String(window.location))) {
453-
currentUrl = String(window.location).split('#')[0]
454-
} else {
455-
currentUrl = String(window.location)
450+
console.log(urlHasHash.test(String(window.location)))
451+
452+
if (urlHasParams.test(currentUrl) || urlHasQueryString.test(currentUrl)) {
453+
currentUrl = currentUrl.split('?')[0]
456454
}
457455

458-
if (currentUrl.slice(- 1) === '#') {
456+
if (urlHasHash.test(currentUrl)) {
457+
currentUrl = currentUrl.split('#')[0]
458+
}
459+
460+
// if (urlHasParams.test(String(window.location)) || urlHasQueryString.test(String(window.location))) {
461+
// currentUrl = String(window.location).split('?')[0]
462+
// } else if (urlHasHash.test(String(window.location))) {
463+
// currentUrl = String(window.location).split('#')[0]
464+
// } else {
465+
// currentUrl = String(window.location)
466+
// }
467+
468+
if (currentUrl.slice(-1) === '#') {
459469
currentUrl = currentUrl.slice(0, -1)
460470
}
461471

0 commit comments

Comments
 (0)