1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use std::collections::HashMap;
pub use yew_router_macro::Routable;
pub trait Routable: Clone + PartialEq {
fn from_path(path: &str, params: &HashMap<&str, &str>) -> Option<Self>;
fn to_path(&self) -> String;
fn routes() -> Vec<&'static str>;
fn not_found_route() -> Option<Self>;
fn recognize(pathname: &str) -> Option<Self>;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AnyRoute {
path: String,
}
impl Routable for AnyRoute {
fn from_path(path: &str, params: &HashMap<&str, &str>) -> Option<Self> {
if params.is_empty() {
Some(Self {
path: path.to_string(),
})
} else {
None
}
}
fn to_path(&self) -> String {
self.path.to_string()
}
fn routes() -> Vec<&'static str> {
vec!["/*path"]
}
fn not_found_route() -> Option<Self> {
Some(Self {
path: "/404".to_string(),
})
}
fn recognize(pathname: &str) -> Option<Self> {
Some(Self {
path: pathname.to_string(),
})
}
}
impl AnyRoute {
pub fn new<S: Into<String>>(pathname: S) -> Self {
Self {
path: pathname.into(),
}
}
}