mefechoel / svelte-navigator

Simple, accessible routing for Svelte
Other
504 stars 39 forks source link

two updates from useLocation() on page reload #41

Open betfix opened 3 years ago

betfix commented 3 years ago

I have the following app:

//App.svelte

<script>
  import { Route, Router } from 'svelte-navigator'
  import Temp from './Temp.svelte'
</script>

<Router>
  <Route path="/temp" component={Temp} />
</Router>
//Temp.svelte
<script>
  import { useLocation } from 'svelte-navigator'
  const location$ = useLocation()
  $: console.log(JSON.stringify($location$))
</script>

After going to /temp path (or refreshing) there are two identical messages in console:

{"pathname":"/temp","hash":"","search":"","state":null}
{"pathname":"/temp","hash":"","search":"","state":null}

Why is the reactive statement called twice if the location didn't change?