use crate::pages::{About, Home}; use yew::prelude::*; use yew_router::{prelude::*, route::Route, switch::Permissive, Switch}; pub struct App { _link: ComponentLink, } #[derive(Switch, Debug, Clone)] pub enum AppRouter { #[to = "/!"] RootPath, #[to = "/about!"] AboutPath, #[to = "/page-not-found"] PageNotFound(Permissive), } pub enum Msg {} impl Component for App { type Message = Msg; type Properties = (); fn create(_: Self::Properties, _link: ComponentLink) -> Self { App { _link } } fn update(&mut self, _msg: Self::Message) -> ShouldRender { true } fn change(&mut self, _: Self::Properties) -> ShouldRender { false } fn view(&self) -> Html { html! {
render = Router::render(|switch: AppRouter | { match switch { AppRouter::RootPath => html!{ }, AppRouter::AboutPath => html!{ }, AppRouter::PageNotFound(Permissive(None)) => html!{"Page not found"}, AppRouter::PageNotFound(Permissive(Some(missed_route))) => html!{format!("Page '{}' not found", missed_route)} } } ) redirect = Router::redirect(|route: Route<()>| { AppRouter::PageNotFound(Permissive(Some(route.route))) }) />
} } }