ItalyPaleAle / svelte-spa-router

Router for SPAs using Svelte 3
MIT License
1.55k stars 106 forks source link

Page doesn't update when navigating within the same route using different params #274

Closed natembennett closed 2 years ago

natembennett commented 2 years ago

If I have a route such as: 'blog/:id: Blog' and I navigate to blog/3, via a link/href from blog/2, the route doesn't update. I have tried using traditional links as well as the imperative push and replace functions provided by this library.

ItalyPaleAle commented 2 years ago

It’s definitely a scenario that should work.

are you able to provide more info? What browser are you using? Can you perhaps share some code to reproduce this as MVP?

StevenRenaux commented 2 years ago

Maybe this one could help you.

https://github.com/ItalyPaleAle/svelte-spa-router/issues/14

I had the same issue and finally had a look in the closed ones.

MerlinB commented 2 years ago

To solve this you can force re-render the component inside of a parent component when the params change.

<script>
  import SomeComponent from "SomeComponent.svelte"

  export let params
</script>

{#key params.someParam}
  <SomeComponent someParam={params.someParam} /> // All code from the route moved into this component
{/key}
ItalyPaleAle commented 2 years ago

The solution proposed by @MerlinB is the correct one :) Going to close this as it is behaving by design

algaly commented 2 years ago

Try replacing your a tag with button and use the push method. Worked for me! (even with animation)