use dioxus_lib::prelude::*; use std::str::FromStr; use crate::{ prelude::{provide_router_context, Outlet}, routable::Routable, router_cfg::RouterConfig, }; /// The props for [`Router`]. #[derive(Props)] pub struct RouterProps { #[props(default, into)] config: Callback<(), RouterConfig>, } impl Clone for RouterProps { fn clone(&self) -> Self { *self } } impl Copy for RouterProps {} impl Default for RouterProps { fn default() -> Self { Self { config: Callback::new(|_| RouterConfig::default()), } } } impl PartialEq for RouterProps { fn eq(&self, _: &Self) -> bool { // prevent the router from re-rendering when the initial url or config changes true } } /// A component that renders the current route. pub fn Router(props: RouterProps) -> Element where ::Err: std::fmt::Display, { use crate::prelude::{outlet::OutletContext, RouterContext}; use_hook(|| { provide_router_context(RouterContext::new( props.config.call(()), schedule_update_any(), )); provide_context(OutletContext:: { current_level: 0, _marker: std::marker::PhantomData, }); }); rsx! { Outlet:: {} } }