Allow routing via regular path

This commit is contained in:
Jeremy Wall 2022-08-21 15:57:46 -04:00
parent ede08f7ef6
commit 6a916fac3c
2 changed files with 12 additions and 9 deletions

View File

@ -24,11 +24,11 @@ pub fn tabbed_view(state: TabState<G>) -> View<G> {
header(class="no-print") { header(class="no-print") {
nav { nav {
ul { ul {
li { a(href="#plan", class="no-print") { "Plan" } " > " li { a(href="/ui/plan", class="no-print") { "Plan" } " > "
} }
li { a(href="#inventory", class="no-print") { "Inventory" } " > " li { a(href="/ui/inventory", class="no-print") { "Inventory" } " > "
} }
li { a(href="#cook", class="no-print") { "Cook" } li { a(href="/ui/cook", class="no-print") { "Cook" }
} }
} }
ul { ul {

View File

@ -15,7 +15,7 @@ use std::fmt::Debug;
use std::rc::Rc; use std::rc::Rc;
use sycamore::prelude::*; use sycamore::prelude::*;
use tracing::{debug, error, instrument}; use tracing::{debug, error, info, instrument};
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast; use wasm_bindgen::JsCast;
use web_sys::Event; use web_sys::Event;
@ -190,11 +190,12 @@ impl DeriveRoute for AppRoutes {
#[instrument] #[instrument]
fn from(input: &(String, String, String)) -> AppRoutes { fn from(input: &(String, String, String)) -> AppRoutes {
debug!(origin=%input.0, path=%input.1, hash=%input.2, "routing"); debug!(origin=%input.0, path=%input.1, hash=%input.2, "routing");
match input.2.as_str() { let (_origin, path, _hash) = input;
let route = match path.as_str() {
"" => AppRoutes::default(), "" => AppRoutes::default(),
"#plan" => AppRoutes::Plan, "/ui/plan" | "/" => AppRoutes::Plan,
"#cook" => AppRoutes::Cook, "/ui/ook" => AppRoutes::Cook,
"#inventory" => AppRoutes::Inventory, "/ui/inventory" => AppRoutes::Inventory,
h => { h => {
// TODO(jwall): Parse the recipe hash // TODO(jwall): Parse the recipe hash
let parts: Vec<&str> = h.splitn(2, "/").collect(); let parts: Vec<&str> = h.splitn(2, "/").collect();
@ -206,6 +207,8 @@ impl DeriveRoute for AppRoutes {
error!(origin=%input.0, path=%input.1, hash=%input.2, "Path not found"); error!(origin=%input.0, path=%input.1, hash=%input.2, "Path not found");
AppRoutes::NotFound AppRoutes::NotFound
} }
} };
info!(route=?route, "Route identified");
route
} }
} }