This content originally appeared on DEV Community and was authored by Dana Woodman
Wanted to do redirects in your SvelteKit endpoints and tried to return { redirect: '/success' }
just to find out it doesn't work?
Well, you're in luck because you can just use the standard Location
header to do redirects:
export async function get() {
// Do some magic here... ✨
return {
headers: { Location: '/success' },
status: 302
}
}
Remember to make sure use the proper status code for your redirect.
Learn more about the Location
header on MDN.
Whelp, that's it for today, hope this saved you some headaches!
Follow me on Dev.to, Twitter and Github for more web dev and startup related content
This content originally appeared on DEV Community and was authored by Dana Woodman

Dana Woodman | Sciencx (2021-04-21T02:29:55+00:00) How to redirect in SvelteKit endpoints. Retrieved from https://www.scien.cx/2021/04/21/how-to-redirect-in-sveltekit-endpoints/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.