How to return data and redirection as before breaking changes? #6054
Replies: 2 comments
-
Did this ever work? return {
status: 302,
redirect: 'access',
props: { logged: false }
}; When you return a redirect, I would have expected the props to get lost, because the user's browser would load the redirect but wouldn't know about the props. Unless Svelte-Kit was handling the redirect internally, which I admit I never looked into deeply. Since you're asking this question, I assume you had working code before, so maybe I was wrong about how redirects got handled. Anyway, in the new world, I would think your code would need to run on the server, i.e. in /// +layout.server.js
// ... rest of load function goes here ...
return {
redirect: '/',
redirectStatus: 302,
logged: false
};
///+layout.js
/// ... rest of load function goes here ...
const data = await parent();
if (data.redirect) {
throw redirect(data.redirectStatus || 302, data.redirect);
} Since the Anyway, give that a try, and if it doesn't work, create a simple repro and open up a bug report. Because if that's supposed to work and it doesn't, then that's a bug. And if that's not supposed to work but you were led to believe that it should work, then that's a documentation issue where the docs need to be clearer. Either way, if that doesn't work, opening an issue is probably appropriate. |
Beta Was this translation helpful? Give feedback.
-
Hello @rmunn. Thanks for your detailed reply. Yes, this code actually runs in two instances that still uses kit 405. The rest of layout code simplified is this. I used logged to switch layout UI look, and redirection to redirect in case is logged in or not. <script>
// import toolbar, sidebar components, etc...
export let siteName;
export let logged;
</script>
<svelte:head>
{#if logged}
<title>{siteName}</title>
{:else}
<title>System Access</title>
{/if}
</svelte:head>
{#if logged}
<!-- sidebar component -->
<slot /> // landed all the site
<!-- footer component -->
{:else}
<slot /> // shows the /access route with a login form without sidebar and footer components
{/if} About the new world, I will test your suggests code and back soon with the results. Thank you! |
Beta Was this translation helpful? Give feedback.
-
Before I have this load code inside
__layout.svelte
:Now I have the new file
+layout.js
with the same code to be changed to new requirements. So how to return data and redirect? For example from:to:
This is bad, I know, but I can't figure how to do it.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions