add navigator and use_navigate hook
This commit is contained in:
6 files changed
+156
-3
No files matched your search
@@ -0,0 +1,20 @@
|
||||
use dioxus::prelude::{ScopeId, ScopeState};
|
||||
use dioxus_router_core::Navigator;
|
||||
use log::error;
|
||||
|
||||
use crate::utils::use_router_internal::use_router_internal;
|
||||
|
||||
#[must_use]
|
||||
pub fn use_navigate(cx: &ScopeState) -> Option<Navigator<ScopeId>> {
|
||||
match use_router_internal(cx) {
|
||||
Some(r) => Some(r.sender.clone().into()),
|
||||
None => {
|
||||
let msg = "`use_navigate` must have access to a parent router";
|
||||
error!("{msg}, will be inactive");
|
||||
#[cfg(debug_assertions)]
|
||||
panic!("{}", msg);
|
||||
#[cfg(not(debug_assertions))]
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user