Redirects in `load` functions break when running client-side
See original GitHub issueDescribe the bug
There appears to be no way to use the new redirect method and disable SSR globally.
Reproduction
- Create a new skeleton project
- Create
src/routes/page.ts
with the contents:
import { redirect } from "@sveltejs/kit";
export function load() {
throw redirect(307, "/about")
}
- Create
src/hooks.ts
with the contents:
import type { Handle } from '@sveltejs/kit'
export const handle: Handle = async ({ event, resolve }) => {
return resolve(event, { ssr: false })
}
- Navigating to root now results in an error page, with the redirect class passed to it, instead of being redirected to “/about”
Repo: https://github.com/WaltzingPenguin/sveltekit-redirect-hooks
Logs
No response
System Info
System:
OS: Windows 10 10.0.19043
CPU: (12) x64 AMD Ryzen 5 1600 Six-Core Processor
Memory: 7.50 GB / 15.95 GB
Binaries:
Node: 16.15.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
npm: 7.20.3 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 104.0.5112.81
Edge: Spartan (44.19041.1266.0), Chromium (104.0.1293.54)
Internet Explorer: 11.0.19041.1566
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.64
@sveltejs/kit: next => 1.0.0-next.413
svelte: ^3.44.0 => 3.49.0
vite: ^3.0.0 => 3.0.8
Severity
blocking an upgrade
Additional Information
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:20
- Comments:40 (23 by maintainers)
Top Results From Across the Web
I am running into multiple problems with load functions - Reddit
Sadly, supabase runs only on the client side and it needs to access localstorage for storing. It only works when it is used...
Read more >Stop using client-side route redirects - Kent C. Dodds
First, the goal of using a client-side redirect (like with Redirect's from prop or similar) is to ensure the user doesn't land on...
Read more >Redirections in HTTP - MDN Web Docs - Mozilla
In HTTP, redirection is triggered by a server sending a special redirect response to a request. Redirect responses have status codes that start ......
Read more >Next.js Redirect from / to another page - Stack Overflow
It handles both server side and client side. The fetch call is the one that actually get the auth token, you might want...
Read more >HTTP redirect codes for SEO explained - ContentKing
Redirects play an important role within SEO, so it's important to know what ... Back button: client-side redirects break the Back button.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Progress update — there’s now an PR against Vite that fixes this issue: https://github.com/vitejs/vite/pull/9848
https://github.com/vitejs/vite/pull/9848
It’s merged 🥹🎉