Replies: 3 comments 3 replies
-
One issue I am still encountering is the onlaod event not working for me: #[inline_props]
pub fn Index(cx: Scope) -> Element {
if condition {
return render! {
"Redirecting ..."
NavigateTo { to: Navigation::ActionMenu }
img {
onload: move |_| {
log::debug!("onlaod triggered");
Navigation::ActionMenu.trigger()
}
}
}
} else {
cx.render(rsx!(...))
}
}``` |
Beta Was this translation helpful? Give feedback.
-
You can navigate to a specific route as defined in this section of the guide: https://dioxuslabs.com/learn/0.4/router/reference/navigation/programmatic. use_navigator just provides a nicer interface over use_router_internal. I think the load event is never triggering on you image because there is no source set that would start loading |
Beta Was this translation helpful? Give feedback.
-
That is because you don't load anything in the img {
onload: move |_| {
panic!()
}
} But this will trigger because there is an image to set: img {
src: "https://avatars.githubusercontent.com/u/66571940?v=4",
onload: move |_| {
panic!()
}
} |
Beta Was this translation helpful? Give feedback.
-
Edit
-> Best solution: #1643 (comment)For a project, I needed to trigger redirection upon a user action among my route. I haven't found a way to do so easily with Dioxus.
use_router_internal(cx)
andRouterContext
methods arepub(crate)
so I can't use them to easyly build a prop.I went with a solution, I want to share it here for anyone who would have a similar need.
I would be glad to take any fix or recommendation for this piece of code :)
How to use
It works in 3 steps:
Navigation
enum to add your routes in theimpl Navigation
fn route(&self)
NavigateTo { to: Navigation::_ }
prop into yourrsx!
blockNavigation::_.triger()
to navigate to the corresponding routeExample
Here's an example of its use with a form.
Prop
Beta Was this translation helpful? Give feedback.
All reactions