use std::borrow::Cow; use crate::pages::{page_home::PageHome, page_not_found::PageNotFound, page_ssh::PageSsh}; use yew::html::IntoPropValue; use yew::prelude::*; use yew::services::ConsoleService; use yew::virtual_dom::VNode; use yew::Component; use yew_router::prelude::*; use yew_router::{router::Router, Switch}; #[derive(Switch, Clone, Debug)] enum AppRoute { // #[at("/ssh/:id")] // Ssh(i32), #[to = "/ssh"] Ssh, #[to = "/!"] Home, #[to = ""] NotFound, } impl Into<&str> for AppRoute { fn into(self) -> &'static str { match self { AppRoute::Ssh => &"/ssh", _ => &"/", } } } impl IntoPropValue>> for AppRoute { fn into_prop_value(self: AppRoute) -> Option> { Some(Cow::Borrowed(self.into())) } } pub struct App {} pub enum Msg {} impl Component for App { type Message = Msg; type Properties = (); fn create(_: Self::Properties, _link: ComponentLink) -> Self { Self {} } fn update(&mut self, _msg: Self::Message) -> ShouldRender { true } fn change(&mut self, _: Self::Properties) -> ShouldRender { false } fn view(&self) -> VNode { html! { <> { self.view_nav() }
render = Router::render(Self::switch) redirect=Router::redirect(|route: Route| { ConsoleService::log(&format!("{:?}", route)); AppRoute::NotFound }) />
} } } impl App { fn view_nav(&self) -> Html { html! { } } fn switch(switch: AppRoute) -> Html { ConsoleService::log(&format!("{:?}", switch)); match switch { // Route::Ssh(ip) => { // html! { } // } AppRoute::Ssh => { html! {} } AppRoute::Home => { html! {} } AppRoute::NotFound => { html! { } } } } }