question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why is redirect from `__layout.svelte` ignored, when an unkown route is hit?

See original GitHub issue

I have a small reproducible example here.

In the above repo, there is __layout.svelte file, that will redirect like this:

return {
  status: 302,
  redirect: '/login'
}

Works great when a route is matched, but if there is an error the redirect is not respected. The load function does actually run, but the browser is not redirected to login.

Is this a bug, not allowed - or do I misunderstand something here?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:19 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
alexbjorligcommented, May 30, 2021

Ok so It’s a bit hard to explain without a conversation for me. But let’s be concrete. Why is a redirect from __layout.svelte ignored? The load function runs, and returns a redirect. The redirect is then, silenty, ignored. That’s is the purpose of this issue to put clarification to. As a developer, I expect a redirect to happen when I return a redirect 😅

1reaction
Rich-Harriscommented, Aug 25, 2022

Going to close this as it’s been obsoleted by the changes in #5748 — it’s no longer possible for an error page to have a load function, meaning this situation can never arise (and errors need to be dealt with more explicitly)

Read more comments on GitHub >

github_iconTop Results From Across the Web

SvelteKit: redirect() not working on server without disabling ssr
I found the problem. The culprit was the status code I was using for redirecting. I was providing the wrong status code 300...
Read more >
SvelteKit API | SK Incognito - Vercel
An option to specify whether pre-render errors should stop the adapt process (default, false) or it should be logged and then ignored. Routing....
Read more >
Recommended - SlideShare
Routing At the heart of SvelteKit is a filesystem-based router. The routes of. +page.js Often, a page will need to load some data...
Read more >
Connect your content to SvelteKit - Sanity.io
In this example, SvelteKit will run the code inside of endpoint route on the server (or in a serverless function if you have...
Read more >
Is it possible to load something and throw redirect in +layout.ts?
The real solution seems to be to just use goto from $app/navigation . It does not reload everything and yet navigates to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found