-
Describe the bugas title, asking for work around Reproduction<script>
import { goto } from '$app/navigation';
goto("/route")
</script> <script>
import { goto } from '$app/navigation';
$: {
setTimeout(() => goto('/route'), 5000);
}
</script> https://stackoverflow.com/a/68187637/6829093 Logs/.svelte-kit/dev/runtime/app/navigation.js:15
throw new Error(`Cannot call ${name}(...) on the server`);
^
Error: Cannot call goto(...) on the server
at Module.eval (/.svelte-kit/dev/runtime/app/navigation.js:15:9)
at Timeout.eval [as _onTimeout] (/src/routes/__layout.svelte:64:43)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)
Node.js v17.2.0 System InfoSystem:
OS: macOS 12.0.1
CPU: (8) arm64 Apple M1
Memory: 98.73 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 17.2.0 - /opt/homebrew/bin/node
Yarn: 1.22.17 - /opt/homebrew/bin/yarn
npm: 8.1.4 - /opt/homebrew/bin/npm
Browsers:
Chrome: 97.0.4692.71
Edge: 96.0.1054.62
Safari: 15.1
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.4
@sveltejs/adapter-static: ^1.0.0-next.22 => 1.0.0-next.22
@sveltejs/kit: next => 1.0.0-next.202
svelte: ^3.44.0 => 3.44.3 Severityannoyance Additional InformationNo response |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 11 replies
-
|
Beta Was this translation helpful? Give feedback.
-
I have updated my project to the newest sveltekit version and using adapter-static and having exactly this issue. the project doesn't build with |
Beta Was this translation helpful? Give feedback.
-
simple way to redirect on the server code is |
Beta Was this translation helpful? Give feedback.
-
This is still really unclear - we can only do I don't want to use a URL parameter like The only thing I can think of is to add a guard that the user does NOT have JS enabled before calling a blanket throw redirect and doing the rest client side. I wish there was an established pattern for this to reference. |
Beta Was this translation helpful? Give feedback.
-
Throw redirect doesn't work on store functions imported. Ok. This solves it : https://stackoverflow.com/a/75786059/12002600 |
Beta Was this translation helpful? Give feedback.
-
Vote to have 'goto' and 'redirect' merged into one easy to use function so we dont have to think about which one to use . We simply use a 'redirect' function and svelte figures out what to do under the hood. Kapish. |
Beta Was this translation helpful? Give feedback.
goto
is not available on the server. You will need to eitherredirect
property(https://kit.svelte.dev/docs/loading#output-redirect)https://kit.svelte.dev/docs/load#redirectsgoto
insideonMount()
if (browser)
from$app/env