fix(Navbar): fix trailing slash inconsistence between environments
This commit is contained in:
parent
66d337255c
commit
b97413e816
1 changed files with 11 additions and 1 deletions
|
|
@ -52,12 +52,22 @@ const links = [
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
const normilizeUrl = (url: string): string => {
|
||||||
|
let newUrl = `${url}`;
|
||||||
|
|
||||||
|
if (newUrl.endsWith('/')) {
|
||||||
|
newUrl = newUrl.slice(0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newUrl;
|
||||||
|
};
|
||||||
|
|
||||||
const setActiveLink = () => {
|
const setActiveLink = () => {
|
||||||
const links =
|
const links =
|
||||||
document.querySelectorAll<HTMLAnchorElement>(`#main-navbar a`);
|
document.querySelectorAll<HTMLAnchorElement>(`#main-navbar a`);
|
||||||
|
|
||||||
links.forEach((link) =>
|
links.forEach((link) =>
|
||||||
link.pathname === location.pathname
|
normilizeUrl(link.pathname) === normilizeUrl(location.pathname)
|
||||||
? link.classList.add('active')
|
? link.classList.add('active')
|
||||||
: link.classList.remove('active'),
|
: link.classList.remove('active'),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue