yew_router/
macro_helpers.rs1pub use urlencoding::{decode as decode_for_url, encode as encode_for_url};
2
3use crate::utils::strip_slash_suffix;
4use crate::Routable;
5
6pub type Router = route_recognizer::Router<String>;
8
9pub fn build_router<R: Routable>() -> Router {
11 let mut router = Router::new();
12 R::routes().iter().for_each(|path| {
13 let stripped_route = strip_slash_suffix(path);
14 router.add(stripped_route, path.to_string());
15 });
16
17 router
18}
19
20pub fn recognize_with_router<R: Routable>(router: &Router, pathname: &str) -> Option<R> {
22 let pathname = strip_slash_suffix(pathname);
23 let matched = router.recognize(pathname);
24
25 match matched {
26 Ok(matched) => R::from_path(matched.handler(), &matched.params().into_iter().collect())
27 .or_else(R::not_found_route),
28 Err(_) => R::not_found_route(),
29 }
30}