Skip to content

Commit 47cab4f

Browse files
committed
Handle absolute paths in Link active check
1 parent c595331 commit 47cab4f

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

packages/wouter/src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,12 @@ export const Link = forwardRef((props, ref) => {
299299
}
300300
});
301301

302+
const targetPathAbsolute =
303+
targetPath[0] === "~" ? targetPath.slice(1) : router.base + targetPath;
304+
302305
// handle nested routers and absolute paths
303306
const href = router.hrefs(
304-
targetPath[0] === "~" ? targetPath.slice(1) : router.base + targetPath,
307+
targetPathAbsolute,
305308
router // pass router as a second argument for convinience
306309
);
307310

@@ -312,7 +315,9 @@ export const Link = forwardRef((props, ref) => {
312315
onClick,
313316
href,
314317
// `className` can be a function to apply the class if this link is active
315-
className: cls?.call ? cls(currentPath === targetPath) : cls,
318+
className: cls?.call
319+
? cls(router.base + currentPath === targetPathAbsolute)
320+
: cls,
316321
children,
317322
ref,
318323
});

0 commit comments

Comments
 (0)