Closed mabentley85 closed 4 years ago
This is probably what happened in #8. I can now reproduce the bug, thanks for the detailed description! I've had a look and I'm quite sure the bug originates in src/history.js, line 81.
It seems as though history.replaceState
is asynchronous and does not immediately update window.location
.
As I see it, there are three possible ways this could be fixed. Either wait a short time before updating the internal location. This is probably fragile and not a great idea. Maybe there is a browser event that is fired when the state is replaced, but I've not seen this in other history implementations, but it should be investigated. Probably the best way to fix it now would be to manually parse the new path and create the next location from that.
Ok, I've identified the actual cause. history.replaceState
is not asynchronous.
The problem was, that the navigation to /login
occures before the onMount
function of Router
is called. The Router
subscribes to changes in the history on mount. However the first change gets lost, because it occures before the Router
has a chance to subscribe to the history.
To fix this, I had to change the behaviour of the history module. It now calles its subscribers (i.e. the Router
) the moment they subscribe, and not only on changes, just like Svelte stores do.
Fixed in 3.1.1
Describe the bug When pointing my browser to
http://localhost:6062/profile
, the URL is properly redirected tohttp://localhost:6062/login
but the login form component is not displayed.To Reproduce Steps to reproduce the behavior:
cd svelte-navigator/example/private-routes
npm install
andnpm start
http://localhost:6062/profile
in web browserExpected behavior When you land on a private route the login form should be displayed.
Screenshots
Desktop (please complete the following information):