summaryrefslogtreecommitdiff
path: root/webapp/src/main.rs
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2022-10-07 10:05:58 -0400
committerKjetil Orbekk <kj@orbekk.com>2022-10-07 10:05:58 -0400
commit01753ebd32e4e0fa8adb11fb02a77720773e3018 (patch)
treee632d32998ae8af88a90d03e1b96882de42a4b07 /webapp/src/main.rs
parent89d2868840a8689b8727c9cfad96eee10c4b517c (diff)
Add multi-page routing to the webapp
Diffstat (limited to 'webapp/src/main.rs')
-rw-r--r--webapp/src/main.rs31
1 files changed, 28 insertions, 3 deletions
diff --git a/webapp/src/main.rs b/webapp/src/main.rs
index ede4390..6fcf59f 100644
--- a/webapp/src/main.rs
+++ b/webapp/src/main.rs
@@ -2,6 +2,7 @@ use data::MyMessage;
#[allow(unused_imports)]
use log::{debug, error, info, warn};
use yew::prelude::*;
+use yew_router::prelude::*;
pub mod bridge_engine;
pub mod card;
pub mod components;
@@ -12,6 +13,14 @@ extern crate wee_alloc;
// Use `wee_alloc` as the global allocator.
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
+#[derive(Clone, Routable, PartialEq)]
+
+enum Route {
+ #[at("/")]
+ Home,
+ #[at("/playground")]
+ Playground,
+}
fn main() {
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
@@ -46,13 +55,29 @@ pub fn app() -> Html {
html! {
<>
- <div class="app">
- <Game />
- </div>
+ <BrowserRouter>
+ <Switch<Route> render={Switch::render(switch)} />
+ </BrowserRouter>
</>
}
}
+fn switch(routes: &Route) -> Html {
+ match routes {
+ Route::Home => html! {
+ <>
+ <p>{ "Hello!" }</p>
+ <p>
+ <Link<Route> to={Route::Playground}>{ "Playground" }</Link<Route>>
+ </p>
+ </>
+ },
+ Route::Playground => html! {
+ <div class="game-layout"><Game /></div>
+ },
+ }
+}
+
#[cfg(test)]
mod tests {
pub fn test_setup() {