add navigator and use_navigate hook

This commit is contained in:
Adrian Wannenmacher committed 2022-12-13 00:09:32 +01:00
1 parent 85ac35c198
commit 0cc0cba482
6 files changed
+156 -3

No files matched your search

+20
View File
@@ -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
}
}
}