import { type RouteDefinition } from '@solidjs/router'
import { cache, createAsync, redirect } from '@solidjs/router'
import { getRequestEvent } from 'solid-js/web'
const exampleAction = cache(async () => {
'use server'
const location = new URL(getRequestEvent()!.request.url)
return redirect(`${location.origin}/target`)
}, 'exampleAction')
export const route = {
load() {
// redirect will start working if uncommented:
// void exampleAction()
},
} satisfies RouteDefinition
export default function Component() {
const data = createAsync(() => exampleAction())
return <h1>Result: {data()}</h1>
}
With the route above, when you navigate to /redirect, it does not redirect you to /target.
Unless you trigger an action with redirect inside route.load or use a relative redirect which starts with / instead of a full URL with the origin, i.e., redirect('/target') works, but redirect('http://localhost:3000/target') does not.
Describe the bug
From https://github.com/solidjs/solid-start/issues/1512#issuecomment-2149045594
Your Example Website or App
N/A
Steps to Reproduce the Bug or Issue
Use the above code in an SSR route
Expected behavior
Redirect happens without a load function.
Screenshots or Videos
No response
Platform
N/A
Additional context
Am fixing this rn