is there a way to start data fetching before component rendering?
react router runs the
loader
before the component. thus making things like redirects easier. is there a way to do this with @solidjs/router?
14 Replies
Solid router has
preload
for this use case
like this? it doesn't work
Use useNavigate in the preload function to do the navigation
Returning stuff from preload doesn’t really do anything
Uncaught Error: <A> and 'use' router primitives can be only used inside a Route.
I mean like
() => useNavigate()(‘/other’)
run this and then click on the link in the /other page. console.log("ran"); will trigger when clicking the <a>. is there a way to not run the component at all?
@Brendonovich 😢
there's not really a better way
really, preload shouldn't be used for this use case in the first place
it's for optimisation. putting a
<Navigate>
in component
is more correcti don't care what is the way, i just want any way at all to not run the component at all if it redirects
i don't think there's a way to guarantee that
if you mean perf by optimization, no. i just think its more correct to have this sense of pages and the loaders run before the pages
i don't mean what you're doing is optimisation, i mean that's what
preload
is fori will try this
solid router doesn't have an equivalent to RR's
loader
since that blocks the route from loading until it's done
solid router expects you to define all the actual logic in the component
and then apply preload as an optimisation on topinteresting