#async navigation
1 messages · Page 1 of 1 (latest)
Yes, you can use the navigator when your async task is finished to go to another page: https://dioxuslabs.com/learn/0.5/router/reference/navigation/programmatic
spawn(async move {
sleep(1000).await;
navigator().push(Route::Home{});
});
Thanks! 🙂
With navigator()
im running into this error: A router must be present to use navigator
Thats my routing:
#[rustfmt::skip]
#[derive(Routable, Clone, PartialEq)]
pub enum Route {
#[redirect("/", || Route::Welcome {})]
#[route("/welcome")]
Welcome {},
#[route("/license")]
License {},
#[route("/progress")]
Progress {},
#[route("/finish")]
Finish {},
}```
Do I have to do any additional Setup like e.g. with use_context_provider
Where are you using navigator?
It needs to be under the router inside the dioxus context
i have a struct called BackgroundWorker where i create another thread using thread::spawn
That will be outside of the dioxus context which means you can't use things like hooks, or consume types from the context API
You could set up a channel that listens for messages on a channel inside dioxus (with a loop in use_future) and navigates to new pages based on those messages
Then you can send messages from your other thread into the dioxus context