use crate::{ExternalNavigationFailure, NavigationTarget, RouterContext};
pub fn navigator() -> Navigator {
Navigator(
dioxus_core::try_consume_context::<RouterContext>()
.expect("A router must be present to use navigator"),
)
}
#[derive(Clone, Copy)]
pub struct Navigator(pub(crate) RouterContext);
impl Navigator {
#[must_use]
pub fn can_go_back(&self) -> bool {
self.0.can_go_back()
}
#[must_use]
pub fn can_go_forward(&self) -> bool {
self.0.can_go_forward()
}
pub fn go_back(&self) {
self.0.go_back();
}
pub fn go_forward(&self) {
self.0.go_forward();
}
pub fn push(&self, target: impl Into<NavigationTarget>) -> Option<ExternalNavigationFailure> {
self.0.push(target)
}
pub fn replace(
&self,
target: impl Into<NavigationTarget>,
) -> Option<ExternalNavigationFailure> {
self.0.replace(target)
}
}