#async navigation

1 messages · Page 1 of 1 (latest)

hot obsidian
#

Hi all, is there currently a way to do navigation from a background thread?
I want to e.g. navigate to another page once a task has finished.
Cheers
Tarcontar

hollow forge
#
spawn(async move {
    sleep(1000).await;
    navigator().push(Route::Home{});
});
hot obsidian
#

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

hollow forge
#

Where are you using navigator?

#

It needs to be under the router inside the dioxus context

hot obsidian
#

i have a struct called BackgroundWorker where i create another thread using thread::spawn

hollow forge
#

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