regalade/app/src/main.rs

60 lines
1.1 KiB
Rust
Raw Normal View History

2023-05-19 11:23:44 +02:00
use log::Level;
use yew::prelude::*;
use yew_router::prelude::*;
#[derive(Routable, Debug, Clone, Copy, PartialEq, Eq)]
enum Route {
#[at("/")]
Index,
#[at("/login")]
Login,
2023-05-19 11:23:44 +02:00
#[at("/404")]
#[not_found]
NotFound,
}
#[function_component]
fn App() -> Html {
html! {
<BrowserRouter>
<main>
<Switch<Route> render={switch} />
</main>
</BrowserRouter>
}
}
fn switch(route: Route) -> Html {
match route {
Route::Index => html! {
<Index />
},
Route::Login => html! {
"Login"
2023-05-19 11:23:44 +02:00
},
Route::NotFound => html! {
"Page not found"
},
}
}
#[function_component]
fn Index() -> Html {
let token = use_state(|| None::<String>);
match &*token {
Some(_) => html! {
"Index"
},
None => html! {
<Redirect<Route> to={Route::Login} />
},
}
}
2023-05-19 11:23:44 +02:00
fn main() {
console_log::init_with_level(Level::Debug).unwrap();
yew::Renderer::<App>::new().render();
}