72 lines
1.6 KiB
Rust
72 lines
1.6 KiB
Rust
use std::collections::HashMap;
|
|
|
|
use yew::{function_component, html, Html};
|
|
use yew_router::history::History;
|
|
|
|
#[derive(yew_router::Routable, PartialEq, Eq, Clone, Debug)]
|
|
pub enum Route {
|
|
#[at("/")]
|
|
Home,
|
|
#[at("/counter")]
|
|
Counter,
|
|
#[at("/echo")]
|
|
Echo,
|
|
#[not_found]
|
|
#[at("/404")]
|
|
NotFound,
|
|
}
|
|
|
|
fn switch(routes: Route) -> Html {
|
|
use super::pages::*;
|
|
|
|
match routes {
|
|
Route::Home => html! { <IndexPage /> },
|
|
Route::Counter => html! { <CounterPage /> },
|
|
Route::NotFound => html! { <NotFound /> },
|
|
Route::Echo => html! { <EchoPage /> },
|
|
}
|
|
}
|
|
|
|
#[function_component]
|
|
pub fn Layout() -> Html {
|
|
use super::components::Nav;
|
|
use yew_router::Switch;
|
|
html! {
|
|
<>
|
|
<Nav />
|
|
<main class="p-6">
|
|
<Switch<Route> render={switch} />
|
|
</main>
|
|
</>
|
|
}
|
|
}
|
|
|
|
#[derive(yew::Properties, PartialEq, Eq, Debug, Default)]
|
|
pub struct ServerAppProps {
|
|
pub url: yew::AttrValue,
|
|
pub queries: HashMap<String, String>,
|
|
}
|
|
|
|
#[function_component]
|
|
pub fn ServerApp(props: &ServerAppProps) -> Html {
|
|
let history = yew_router::history::AnyHistory::from(yew_router::history::MemoryHistory::new());
|
|
history
|
|
.push_with_query(&*props.url, &props.queries)
|
|
.unwrap();
|
|
|
|
html! {
|
|
<yew_router::Router history={history}>
|
|
<Layout />
|
|
</yew_router::Router>
|
|
}
|
|
}
|
|
|
|
#[function_component]
|
|
pub fn App() -> Html {
|
|
html! {
|
|
<yew_router::BrowserRouter>
|
|
<Layout />
|
|
</yew_router::BrowserRouter>
|
|
}
|
|
}
|