Why is redirect from `__layout.svelte` ignored, when an unkown route is hit?
See original GitHub issueI 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:
- Created 2 years ago
- Reactions:1
- Comments:19 (15 by maintainers)
Top 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 >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 FreeTop 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
Top GitHub Comments
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 😅
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)