Redirect in createResource
Hey, I don't quite understand where to use redirect, thought it was meant to run server-side but doesnt appear to work inside a deferred createResource. What do I need to do to make this work?
16 Replies
Does it work if you wrap the handle redirect function in a query()?
Do you know when that was added? Currently on solid-start 1.0.5 and solid 1.8.18. I didn't see it popping up as an import when I tried. I tried to update earlier this week but was facing hydration errors and just ended up reverting.
It might be called "cache" instead then. It was renamed
Let me try
Got it to work when swapping to cache and createAsync. Thanks @brenelz
Oh ok... So it probably doesn't work with resources
Might with cache but I swapped to createAsync as I was reading some other documentation, I'll try with createResource in a moment.
Works with create resource as well, not sure it matters here either way since it's just a throwaway to redirect
I thought maybe you had to use the signal from createAsync but I guess not
Yeah unsure, do you happen to know why it requires a cache/query for this by the way? Bit confused why it can't just run in a SSRed function
Also you might be able to use the navigate component if you just need to redirect
https://docs.solidjs.com/solid-router/reference/components/navigate
Navigate runs on client though correct?
This is just for a catch-all route to redirect to /404 if they go to a unspecified or protected route. Guess it doesn't really matter too much if it's client vs ssr in fairness, but I just preferred it on the server.
Yeah not sure
No worries, regardless thanks for your help on solving it.
I think the cache wrapper is the one that intercepts and handles the redirect
Ahh interesting.
I might go look into the internals of it later
There is also a built in 404 catch all route in solidstart?
I wanted it to redirect though.
I use the catchall with "*404" then redirect to /404