-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why is redirect not supported from __error.svelte cmpt? #1574
Comments
It looks like the desired use case here is to redirect instead of showing a 404 page: Related bug about not being able to redirect from a layout page: #1575 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
One danger here is a possible infinite redirect if you redirect to a page that has an error or can't be found, etc. But as long as the infinite redirect is happening in the browser so that the developer can see it (which I think it would) then that's their problem |
We just need to add a check for
|
From what i could try, for 404s,
and goes straight to I haven't tested for errors other than 404 yet, behaviour probably is different. |
Ah, yeah, it looks like 404 and the rest are implemented differently. My last comment is about how you'd implement for the rest One thing we'd need to test is to make sure you can return a redirect status on |
Some work is being done here, still in draft. I think i handled redirections from
Would there be other cases i missed ? Let me know if anything pops to mind. I'll probably open a PR in the days to come. P.S: There is also #1575 that could be handled in this PR, but maybe i should work on it in a different PR. What do you think ? |
That's great! Thanks so much It looks good so far. Tests would be a good idea. You could add them in #1575 could be handled in the same PR or a different PR |
I talked about this with the rest of the maintainers at today's maintainer's meeting. Folks suggested you could already do this in one of a couple ways:
There was a consensus that redirecting on error pages is in general a bit of a weird thing to do and so folks didn't want to add support for it directly into the router, but instead suggested it be handled in these other ways since it's a relatively uncommon use case |
Hey I've added a [fallthough].svelte but it doesn't catch 404 form urls with subsequent path: |
@PlopTheReal I don't know if you were able to solve it, but I managed to get a catch-all 404 redirect working by adding a <script>
import { page } from '$app/stores';
import { goto } from '$app/navigation';
if ($page.status === 404) {
goto('/');
}
</script> |
I have a small reproducible example here.
In the
__error.svelte
cmpt I have thrown in a redirect like this in the load function:But this is not working. Is this a bug, not allowed - or do I misunderstand something here?
The text was updated successfully, but these errors were encountered: