frontend/src/main.rs

56 lines
1.2 KiB
Rust

mod content;
mod state;
mod topbar;
use content::{error, home::Home};
use state::State;
use std::rc::Rc;
use topbar::TopBar;
use yew::prelude::*;
use yew_router::prelude::*;
#[derive(Clone, Routable, PartialEq)]
enum Route {
#[at("/")]
Home,
#[at("/services")]
Services,
#[at("/community")]
Community,
#[at("/about")]
About,
#[not_found]
#[at("/404")]
NotFound,
}
fn switch(routes: Route) -> Html {
match routes {
Route::Home => html! { <Home/> },
Route::Services => html! {<h1>{ "Services" }</h1>},
Route::Community => html! {<h1>{ "Community" }</h1>},
Route::About => html! {<h1>{ "About" }</h1>},
Route::NotFound => html! { <error::NotFound/> },
}
}
#[function_component]
fn App() -> Html {
let state = use_memo(|_| State::default(), ());
html! {
<ContextProvider<Rc<State>> context={state}>
<TopBar/>
<main>
<BrowserRouter>
<Switch<Route> render={switch} />
</BrowserRouter>
</main>
</ContextProvider<Rc<State>>>
}
}
fn main() {
yew::Renderer::<App>::new().render();
}