svelte-navigator
svelte-navigator copied to clipboard
State is replaced when navigating to the same page but with no search path
Describe the bug A clear and concise description of what the bug is.
When navigating from "/some/page?from=1" to "/some/page" the history state is replaced instead of being pushed.
To Reproduce Steps to reproduce the behavior:
- Go to "/some/page?from=1"
- Click on a link that leads to "/some/page"
- Hit browser's "back" button
- You won't be at expected "/some/page?from=1" page
Expected behavior A clear and concise description of what you expected to happen.
Browser's "back" button makes you go back to the previous page.
Additional context Add any other context about the problem here.
The following patch fixes the issue:
diff --git a/src/Link.svelte b/src/Link.svelte
index 3c00f09..6ba48c7 100644
--- a/src/Link.svelte
+++ b/src/Link.svelte
@@ -33,7 +33,7 @@
// when for example an :id changes in the parent Routes path
$: href = resolve(to, $location);
$: isPartiallyCurrent = startsWith($location.pathname, href);
- $: isCurrent = href === $location.pathname;
+ $: isCurrent = href === $location.pathname + $location.search;
$: ariaCurrent = isCurrent ? { "aria-current": "page" } : {};
$: props = (() => {
if (isFunction(getProps)) {
Hey there! Yes, that's a bug. I think your suggested fix doesn't quite cut it though, as it would cause the aria-current attribute to not be applied in some cases. But by introducing a new variable that checks if there is an exact match, this can be fixed. I'll look into it :)
Fixed in 3.2.0