1use yew::prelude::*;
4
5use crate::history::*;
6use crate::navigator::Navigator;
7use crate::routable::Routable;
8use crate::router::{LocationContext, NavigatorContext};
9
10#[hook]
12pub fn use_navigator() -> Option<Navigator> {
13 use_context::<NavigatorContext>().map(|m| m.navigator())
14}
15
16#[hook]
18pub fn use_location() -> Option<Location> {
19 Some(use_context::<LocationContext>()?.location())
20}
21
22#[hook]
31pub fn use_route<R>() -> Option<R>
32where
33 R: Routable + 'static,
34{
35 let navigator = use_navigator()?;
36 let location = use_location()?;
37 let path = navigator.strip_basename(location.path().into());
38
39 R::recognize(&path)
40}