use yew::prelude::*;
use crate::prelude::*;
#[derive(Properties, PartialEq, Clone)]
pub struct SwitchProps<R>
where
R: Routable,
{
pub render: Callback<R, Html>,
#[prop_or_default]
pub pathname: Option<String>,
}
#[component]
pub fn Switch<R>(props: &SwitchProps<R>) -> Html
where
R: Routable + 'static,
{
let route = use_route::<R>();
let route = props
.pathname
.as_ref()
.and_then(|p| R::recognize(p))
.or(route);
match route {
Some(route) => props.render.emit(route),
None => {
tracing::warn!("no route matched");
Html::default()
}
}
}