DEV Community

Cover image for How to redirect in SvelteKit endpoints

How to redirect in SvelteKit endpoints

danawoodman profile image Dana Woodman ・1 min read

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
Enter fullscreen mode Exit fullscreen mode

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, Twitter and Github for more web dev and startup related content

Discussion (0)

Editor guide