-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: handling 404 when redirect from +layout.ts in SPA mode #11771
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
Conversation
|
Thanks for opening this PR, although I’m not sure if this is the right solution. We need to load the root layout when rendering the root error page. I’m guessing the tests are failing because of the root layout node being omitted. I think we should be catching the error instead as I explained here #11099 (comment) adding a test for this scenario should help with testing the solution |
Thanks for pointing that out! And I'm working on your solution |
I've marked this as a draft for now. Please hit "ready for review" when it's ready for another look |
} catch (err) { | ||
return await get_navigation_result_from_branch({ | ||
url, | ||
params, | ||
branch: [root_error], | ||
status, | ||
error, | ||
route: null | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is quite right. We need to differentiate between Redirect errors and other errors instead of loading the default error page without the root layout results (which would cause more errors when it loads without the expected layout data). A redirect should navigate to the redirected URL while other errors should render the static fallback error page (but the client doesn't have access to that so I think we just use server_fallback
or native_navigation
?)
|
||
export async function load({ route }) { | ||
//@ts-ignore | ||
if (route.id == '/bad-route' || route.id == '/good-route') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
route.id
will always return null
if the route doesn't exist. We should check for url.pathname
instead so that this condition passes when we navigate to /bad-route
.
closed in favour of #12005 |
fixes #11099
When redirect to an unknow route in SPA mode, which has a root load function in
+layout.ts
, it will fallback to the root+error.svelte
instead of a blank page.Issue #11494 seems to be releated
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits