Open slyons opened 11 months ago
In Dioxus, parsing the route happens through a FromStr implementation. That is nice for compatibility with the rust ecosystem, but it means you cannot access any non-global hooks inside of any parsing logic.
Adding a guard (which is just a wrapper over a redirect) would be a nice addition. It could just be a redirect that returns Option<Route>
and continues to children if it returns None:
#[rustfmt::skip]
#[derive(Clone, Debug, PartialEq, Routable)]
enum Route {
#[guard("/:id", |id: usize| id.is_even().then(|| Index {})]
#[route("/")]
BlogList {
id: usize
},
#[end_guard]
#[route("/")]
Index {},
}
Note: this should not be used for anything that needs to be securely hidden. Because everything runs on the frontend, you could get past the guard pretty easily
@ealmloff Note: this should not be used for anything that needs to be securely hidden. Because everything runs on the frontend, you could get past the guard pretty easily
Would the implementation of #[guard]
be any different where fullstack is used?
In dioxus fullstack, we could bundle split the protected routes and only serve the route if the guard condition is met to more securely hide content.
Similar to Leptos it would be great if there was a way to put
Route
s behind a condition. If the condition (based on a simple function that can use all the same hooks as Elements) isn't true, the Route is redirected much like theredirect
attribute.