use yew::prelude::*;
use crate::history::*;
use crate::navigator::Navigator;
use crate::routable::Routable;
use crate::router::{LocationContext, NavigatorContext};
#[hook]
pub fn use_navigator() -> Option<Navigator> {
use_context::<NavigatorContext>().map(|m| m.navigator())
}
#[hook]
pub fn use_location() -> Option<Location> {
Some(use_context::<LocationContext>()?.location())
}
#[hook]
pub fn use_route<R>() -> Option<R>
where
R: Routable + 'static,
{
let navigator = use_navigator()?;
let location = use_location()?;
let path = navigator.strip_basename(location.path().into());
R::recognize(&path)
}