Skip to content

Commit 712d3b1

Browse files
author
0xOZ
committed
reverted Link.tsx changes & updated url.ts isHrefActive() behavior
1 parent fb37954 commit 712d3b1

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/components/Link.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ export const BaseLink = forwardRef(function Link(
5858
ref
5959
) {
6060
const { asPath } = useRouter()
61-
const cleanAsPath = asPath.replace(/#.*/, "");
6261
const { flipForRtl } = useRtlFlip()
6362

6463
let href = (to ?? hrefProp) as string
6564

66-
const isActive = url.isHrefActive(href, cleanAsPath, isPartiallyActive)
65+
const isActive = url.isHrefActive(href, asPath, isPartiallyActive)
6766
const isDiscordInvite = url.isDiscordInvite(href)
6867
const isPdf = url.isPdf(href)
6968
const isExternal = url.isExternal(href)

src/lib/utils/url.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,18 @@ export const sanitizeHitUrl = (url: string): string =>
2828
.replace("#content", "")
2929
.replace("#top", "")
3030

31+
// remove any query params or hashes from the path
32+
export const cleanPath = (path: string): string => path.replace(/[$#].+$/, "")
33+
3134
export const isHrefActive = (
3235
href: string,
3336
pathname: string,
3437
isPartiallyActive?: boolean
35-
) => (isPartiallyActive ? pathname.startsWith(href) : pathname === href)
38+
) =>
39+
isPartiallyActive ? pathname.startsWith(href) : cleanPath(pathname) === href
3640

3741
export const isHash = (href: string): boolean => href.startsWith("#")
3842

39-
// remove any query params or hashes from the path
40-
export const cleanPath = (path: string): string => path.replace(/[$#].+$/, "")
41-
4243
export const addSlashes = (href: string): string => {
4344
if (isExternal(href)) return href
4445
return join("/", href, "/")

0 commit comments

Comments
 (0)