mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-02 14:16:39 +01:00
More accurate isActive
This commit is contained in:
parent
6e4110714c
commit
10471090f5
1 changed files with 12 additions and 1 deletions
|
@ -19,7 +19,18 @@ const Link = forwardRef((props, ref) => {
|
|||
let hash = (location.hash || '').replace(/^#/, '').trim();
|
||||
if (hash === '') hash = '/';
|
||||
const { to, ...restProps } = props;
|
||||
// TODO: maybe better pass hash into URL to deconstruct the pathname and search, then decodeURIComponent them
|
||||
|
||||
// Handle encodeURIComponent of searchParams values
|
||||
if (!!hash && hash !== '/') {
|
||||
const parsedHash = new URL(hash, location.origin); // Fake base URL
|
||||
if (parsedHash.searchParams.size) {
|
||||
const searchParamsStr = Array.from(parsedHash.searchParams.entries())
|
||||
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
||||
.join('&');
|
||||
hash = parsedHash.pathname + '?' + searchParamsStr;
|
||||
}
|
||||
}
|
||||
|
||||
const isActive = hash === to || decodeURIComponent(hash) === to;
|
||||
return (
|
||||
<a
|
||||
|
|
Loading…
Reference in a new issue