use crate::{GenericRouterContext, NavigationTarget, Routable, RoutingCallback};
use dioxus_core::Element;
use std::sync::Arc;
pub struct RouterConfig<R> {
pub(crate) failure_external_navigation: fn() -> Element,
pub(crate) on_update: Option<RoutingCallback<R>>,
}
#[cfg(not(feature = "html"))]
impl<R> Default for RouterConfig<R> {
fn default() -> Self {
Self {
failure_external_navigation: || VNode::empty(),
on_update: None,
}
}
}
#[cfg(feature = "html")]
impl<R> Default for RouterConfig<R> {
fn default() -> Self {
Self {
failure_external_navigation: crate::components::FailureExternalNavigation,
on_update: None,
}
}
}
impl<R> RouterConfig<R>
where
R: Routable,
{
pub fn on_update(
self,
callback: impl Fn(GenericRouterContext<R>) -> Option<NavigationTarget<R>> + 'static,
) -> Self {
Self {
on_update: Some(Arc::new(callback)),
..self
}
}
#[cfg_attr(
feature = "html",
doc = "Defaults to [`crate::components::FailureExternalNavigation`]."
)]
pub fn failure_external_navigation(self, component: fn() -> Element) -> Self {
Self {
failure_external_navigation: component,
..self
}
}
}