-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling goto
directly causes server side navigation
#1764
Comments
yes pretty sure this is the problem. I'm too lazy to test it but you could try listening for the Also why do you not unconditionally goto (so don't check for browser). I haven't tested that either though. |
If you want to immediately redirect the load function seems to be able to return a "redirect" property. I didn't test it but it may work better. |
Thanks for the feedback and suggestions, For my particular use-case, I need to ensure client-side redirection. Apart from my use-case, I think goto should trigger client-side navigation when called directly, and I was not sure why it is causing a refresh on some cases, thus I created the issue. |
Thanks for the suggestion, I added another test with |
It's because rendering starts before the router is initialized:
Rendering the component calls |
Calling
goto
directly causes page refresh and server-side navigation.To Reproduce
I prepared a skeleton project at https://github.com/zeckon/sveltekit-goto
there are 3 routes:
/test1
/test2
/test3
all directly call
goto('/')
(index.svelte)inside
index.svelte
it console.logsbrowser
orssr
based on envtest1.svelte:
index.svelte:
Expected behavior
Expectation is to see only
client
on browser logs, and nothing in server console.❌ /test1 and /test2 also run on server (because of page refresh) and outputs
ssr
to console✔️ /test3 wraps
goto
insidesetTimeout
only does client-side navigation outputs onlyclient
in browser as expectedAdditional context
❔ can this be happening because client side router was not ready yet when goto was called.
✔️ calling goto after a fetch, or with user interaction (e.g. onClick) also triggers only client side navigation.
The text was updated successfully, but these errors were encountered: