What's the prescribed approach for performing a data lookup and redirect on the server side using cargo-leptos? #2037
-
My situation for routing looks someting like this:
The approach that I am considering is:
What I'm trying to confirm is if the redirect from the root page to the feed specific page happens on the server itself or does it take a round trip where the server sends a redirect request to the client browser and then the browser makes a subsequent request to the the feed URL and then the server sends generated content for the same? Is it possible to perform the redirection on the server and return a rendered page of the feed on the initial navigation without a round trip from the browser? I'm trying to create an experience with the fastest time to initial render and this round trip would hinder that. Is this the right way to think about this? An additional question around redirect logic. The redirect logic here looks like it will be called from the Axum router here. In the above case, for the behaviour I want, where should I list the router handler for the redirect to happen on the root domain? What should be my router entry? I imagine I can't set up the above wanted behaviour in the Leptos Router because the Leptos Router needs something that implements Thoughts? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
If all you need is to fetch a list of posts from the database and show it in a listview and detail view, then you don't need redirect. Check this example: https://github.com/leptos-rs/leptos/blob/main/examples/ssr_modes/src/app.rs |
Beta Was this translation helpful? Give feedback.
create_blocking_resource
to call that server functionThis may seem overly complicated but the benefit is that it behaves in exactly the same way on the client or the server: i.e., if someone initially loads
/
, it will serve them the redirect from the server. If they then navigate back to/
on the client, it will call the server to get a new redirect URL and go there from the client.