In my project, I want users that go to /account to be redirected to /account/profile. The first solution I came up with is simply putting a
goto("/account/profile")
and that worked, but even on local server you could still briefly see the /account page contents. I then turned to using the redirect function, because I didn't want to start hacking around trying to make it render the /account/profile page and change the URL. When I tried using redirect in a components script tag, it changed the URL but displayed an error page with "500 Internal Server Error". Then I tried using redirect in a +page.ts file, but that just produced the blank white page.
Reproduction
Create a SvelteKit app and create the folders src/account and src/account/profile
Create server.ts in src/account and +page.svelte in src/account/profile
Make a load function in server.ts that throws redirect:
import { redirect } from "@sveltejs/kit"
export async function load() {
throw redirect(300, "/account/profile")
}
4. Add any element in `+page.ts`:
```html
<h1>This is an h1</h1>
Run npm run dev & visit the dev server at /account in the browser
Describe the bug
In my project, I want users that go to
/account
to be redirected to/account/profile
. The first solution I came up with is simply putting aand that worked, but even on local server you could still briefly see the
/account
page contents. I then turned to using theredirect
function, because I didn't want to start hacking around trying to make it render the/account/profile
page and change the URL. When I tried using redirect in a components script tag, it changed the URL but displayed an error page with "500 Internal Server Error". Then I tried using redirect in a+page.ts
file, but that just produced the blank white page.Reproduction
src/account
andsrc/account/profile
server.ts
insrc/account
and+page.svelte
insrc/account/profile
load
function inserver.ts
that throws redirect:export async function load() { throw redirect(300, "/account/profile") }
npm run dev
& visit the dev server at/account
in the browserLogs
System Info
Severity
annoyance
Additional Information
I used npm for this, not pnpm. I can work around it with the hack mentioned in the description, but if there is a better way/fix let me know.