Skip to content

Commit

Permalink
feat(router): add query params to router example
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechu10 committed Nov 3, 2024
1 parent d77932c commit a068fcc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion examples/router/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use sycamore::prelude::*;
use sycamore_router::{HistoryIntegration, Route, Router};
use sycamore_router::{create_query, HistoryIntegration, Route, Router};

#[derive(Route, Clone)]
enum AppRoutes {
Expand All @@ -11,6 +11,8 @@ enum AppRoutes {
Wildcard { path: Vec<String> },
#[to("/uint-capture/<unit>")]
Unit(u32),
#[to("/query-params")]
QueryParams,
#[not_found]
NotFound,
}
Expand All @@ -32,6 +34,8 @@ fn App() -> View {
br {}
a(href="/uint-capture/42") {"Unit: 42"}
br {}
a(href="/query-params") {"Query Params"}
br {}
a(href="/not-found") {"Not Found"}
br {}

Expand All @@ -51,6 +55,14 @@ fn App() -> View {
AppRoutes::Unit(unit) => view! {
h1 { "Unit: " (unit) }
},
AppRoutes::QueryParams => {
let q = create_query("q");
view! {
h1 { "Query Params" }
a(href="?q=a") { "A" } a(href="?q=b") { "B" }
p { "Query: " (q.get_clone().unwrap_or_default()) }
}
}
AppRoutes::NotFound => view! {
h1 { "Not Found" }
},
Expand Down

0 comments on commit a068fcc

Please sign in to comment.