dioxus/packages/router/examples/simple_routes.rs

205 lines
5.5 KiB
Rust
Raw Normal View History

2022-12-09 00:15:04 +00:00
use dioxus::prelude::*;
2023-05-24 00:09:24 +00:00
use std::str::FromStr;
2022-12-09 00:15:04 +00:00
Implement LiveView Router Integration (#1505) * Fix GoForwardButton calling can_go_back instead of can_go_forward * Add first draft of LiveviewHistory * Add external URL redirect * Lock evaluator channel outside loop * Add liveview to router examples * fixup! Add liveview to router examples * Communicate with liveview server on page load * Add PopState event to Liveview routing * Call updater callback from liveview history * Add rudimentary PopState functionality to liveview router. * Fix linter errors * Refactor * Fix navigator external redirection not working. * Add go back and go forward buttons to router examples * Finish functionality for timeline stack in liveview router * Add docs to LiveviewHistory * Replace Liveview history context attachment with constructor that takes context * Fix go forward/backward history/future shuffle * Support history across entire liveview session, if contiguous page jumps. * Remove unnecessary bounds * Add query and hash to location string * Run rustfmt * fix: Update server function docs link (#1489) * liveview: Add `interpreter_glue_relative_uri (#1481) * liveview: Add `interpreter_glue_relative_uri` By utilizing `window.location.host` in the client-side JavaScript, we can easily derive the WebSocket URI from a relative path URI. This approach obviates the need for host address retrieval on the server side, unlike the method of serving glue code in liveview using `interpreter_glue`. * liveview: Merge `.._relative_url` functionality - Merged `.._relative_url` to current API `interpreter_glue`. - Edit axum example to work with new feature. * liveview: Fix clippy warning * Rename modules to use snake_case (#1498) * Change Scope into &ScopeState * Move synchronization of state into router and make it opt-in --------- Co-authored-by: Marc Espín <mespinsanz@gmail.com> Co-authored-by: Seungwoo Kang <ki6080@gmail.com> Co-authored-by: Leonard <tigerros.gh@gmail.com> Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
2023-10-26 19:19:51 +00:00
#[cfg(feature = "liveview")]
#[tokio::main]
async fn main() {
use axum::{extract::ws::WebSocketUpgrade, response::Html, routing::get, Router};
let listen_address: std::net::SocketAddr = ([127, 0, 0, 1], 3030).into();
let view = dioxus_liveview::LiveViewPool::new();
let app = Router::new()
.fallback(get(move || async move {
Html(format!(
r#"
<!DOCTYPE html>
<html>
<head></head>
<body><div id="main"></div></body>
{glue}
</html>
"#,
glue = dioxus_liveview::interpreter_glue(&format!("ws://{listen_address}/ws"))
))
}))
.route(
"/ws",
get(move |ws: WebSocketUpgrade| async move {
ws.on_upgrade(move |socket| async move {
_ = view.launch(dioxus_liveview::axum_socket(socket), app).await;
Implement LiveView Router Integration (#1505) * Fix GoForwardButton calling can_go_back instead of can_go_forward * Add first draft of LiveviewHistory * Add external URL redirect * Lock evaluator channel outside loop * Add liveview to router examples * fixup! Add liveview to router examples * Communicate with liveview server on page load * Add PopState event to Liveview routing * Call updater callback from liveview history * Add rudimentary PopState functionality to liveview router. * Fix linter errors * Refactor * Fix navigator external redirection not working. * Add go back and go forward buttons to router examples * Finish functionality for timeline stack in liveview router * Add docs to LiveviewHistory * Replace Liveview history context attachment with constructor that takes context * Fix go forward/backward history/future shuffle * Support history across entire liveview session, if contiguous page jumps. * Remove unnecessary bounds * Add query and hash to location string * Run rustfmt * fix: Update server function docs link (#1489) * liveview: Add `interpreter_glue_relative_uri (#1481) * liveview: Add `interpreter_glue_relative_uri` By utilizing `window.location.host` in the client-side JavaScript, we can easily derive the WebSocket URI from a relative path URI. This approach obviates the need for host address retrieval on the server side, unlike the method of serving glue code in liveview using `interpreter_glue`. * liveview: Merge `.._relative_url` functionality - Merged `.._relative_url` to current API `interpreter_glue`. - Edit axum example to work with new feature. * liveview: Fix clippy warning * Rename modules to use snake_case (#1498) * Change Scope into &ScopeState * Move synchronization of state into router and make it opt-in --------- Co-authored-by: Marc Espín <mespinsanz@gmail.com> Co-authored-by: Seungwoo Kang <ki6080@gmail.com> Co-authored-by: Leonard <tigerros.gh@gmail.com> Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
2023-10-26 19:19:51 +00:00
})
}),
);
println!("Listening on http://{listen_address}");
2024-02-16 02:59:57 +00:00
let listener = tokio::net::TcpListener::bind(&listen_address)
.await
.unwrap();
axum::serve(listener, app.into_make_service())
Implement LiveView Router Integration (#1505) * Fix GoForwardButton calling can_go_back instead of can_go_forward * Add first draft of LiveviewHistory * Add external URL redirect * Lock evaluator channel outside loop * Add liveview to router examples * fixup! Add liveview to router examples * Communicate with liveview server on page load * Add PopState event to Liveview routing * Call updater callback from liveview history * Add rudimentary PopState functionality to liveview router. * Fix linter errors * Refactor * Fix navigator external redirection not working. * Add go back and go forward buttons to router examples * Finish functionality for timeline stack in liveview router * Add docs to LiveviewHistory * Replace Liveview history context attachment with constructor that takes context * Fix go forward/backward history/future shuffle * Support history across entire liveview session, if contiguous page jumps. * Remove unnecessary bounds * Add query and hash to location string * Run rustfmt * fix: Update server function docs link (#1489) * liveview: Add `interpreter_glue_relative_uri (#1481) * liveview: Add `interpreter_glue_relative_uri` By utilizing `window.location.host` in the client-side JavaScript, we can easily derive the WebSocket URI from a relative path URI. This approach obviates the need for host address retrieval on the server side, unlike the method of serving glue code in liveview using `interpreter_glue`. * liveview: Merge `.._relative_url` functionality - Merged `.._relative_url` to current API `interpreter_glue`. - Edit axum example to work with new feature. * liveview: Fix clippy warning * Rename modules to use snake_case (#1498) * Change Scope into &ScopeState * Move synchronization of state into router and make it opt-in --------- Co-authored-by: Marc Espín <mespinsanz@gmail.com> Co-authored-by: Seungwoo Kang <ki6080@gmail.com> Co-authored-by: Leonard <tigerros.gh@gmail.com> Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
2023-10-26 19:19:51 +00:00
.await
.unwrap();
}
#[cfg(not(feature = "liveview"))]
2022-12-09 00:15:04 +00:00
fn main() {
launch(app)
}
fn app() -> Element {
rsx! {
Router::<Route> {}
}
2023-05-24 00:09:24 +00:00
}
2022-12-09 00:15:04 +00:00
#[component]
fn UserFrame(user_id: usize) -> Element {
2024-01-16 19:18:46 +00:00
rsx! {
Implement LiveView Router Integration (#1505) * Fix GoForwardButton calling can_go_back instead of can_go_forward * Add first draft of LiveviewHistory * Add external URL redirect * Lock evaluator channel outside loop * Add liveview to router examples * fixup! Add liveview to router examples * Communicate with liveview server on page load * Add PopState event to Liveview routing * Call updater callback from liveview history * Add rudimentary PopState functionality to liveview router. * Fix linter errors * Refactor * Fix navigator external redirection not working. * Add go back and go forward buttons to router examples * Finish functionality for timeline stack in liveview router * Add docs to LiveviewHistory * Replace Liveview history context attachment with constructor that takes context * Fix go forward/backward history/future shuffle * Support history across entire liveview session, if contiguous page jumps. * Remove unnecessary bounds * Add query and hash to location string * Run rustfmt * fix: Update server function docs link (#1489) * liveview: Add `interpreter_glue_relative_uri (#1481) * liveview: Add `interpreter_glue_relative_uri` By utilizing `window.location.host` in the client-side JavaScript, we can easily derive the WebSocket URI from a relative path URI. This approach obviates the need for host address retrieval on the server side, unlike the method of serving glue code in liveview using `interpreter_glue`. * liveview: Merge `.._relative_url` functionality - Merged `.._relative_url` to current API `interpreter_glue`. - Edit axum example to work with new feature. * liveview: Fix clippy warning * Rename modules to use snake_case (#1498) * Change Scope into &ScopeState * Move synchronization of state into router and make it opt-in --------- Co-authored-by: Marc Espín <mespinsanz@gmail.com> Co-authored-by: Seungwoo Kang <ki6080@gmail.com> Co-authored-by: Leonard <tigerros.gh@gmail.com> Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
2023-10-26 19:19:51 +00:00
pre { "UserFrame{{\n\tuser_id:{user_id}\n}}" }
div { background_color: "rgba(0,0,0,50%)",
2023-05-24 00:09:24 +00:00
"children:"
2023-07-26 01:14:48 +00:00
Outlet::<Route> {}
2022-12-09 03:11:31 +00:00
}
2022-12-09 00:15:04 +00:00
}
}
#[component]
fn Route1(user_id: usize, dynamic: usize, query: String) -> Element {
2024-01-16 19:18:46 +00:00
rsx! {
2023-05-24 00:09:24 +00:00
pre {
"Route1{{\n\tuser_id:{user_id},\n\tdynamic:{dynamic},\n\tquery:{query}\n}}"
2023-05-24 00:09:24 +00:00
}
Link {
to: Route::Route1 {
user_id,
dynamic,
query: String::new(),
},
2023-05-24 00:09:24 +00:00
"Route1 with extra+\".\""
}
p { "Footer" }
Link {
to: Route::Route3 {
dynamic: String::new(),
},
2023-05-24 00:09:24 +00:00
"Home"
2022-12-09 03:11:31 +00:00
}
}
}
#[component]
fn Route2(user_id: usize) -> Element {
2024-01-16 19:18:46 +00:00
rsx! {
pre { "Route2{{\n\tuser_id:{user_id}\n}}" }
{(0..user_id).map(|i| rsx!{ p { "{i}" } })}
2023-05-24 00:09:24 +00:00
p { "Footer" }
Link {
to: Route::Route3 {
dynamic: String::new(),
},
2023-05-24 00:09:24 +00:00
"Home"
2022-12-09 03:11:31 +00:00
}
2022-12-09 00:15:04 +00:00
}
}
#[component]
fn Route3(dynamic: String) -> Element {
let mut current_route_str = use_signal(String::new);
let current_route = use_route();
2023-06-01 14:45:31 +00:00
let parsed = Route::from_str(&current_route_str.read());
2023-05-24 00:09:24 +00:00
let site_map = Route::SITE_MAP
.iter()
.flat_map(|seg| seg.flatten().into_iter())
.collect::<Vec<_>>();
let navigator = use_navigator();
2024-01-05 01:21:06 +00:00
2024-01-16 19:18:46 +00:00
rsx! {
2023-05-24 00:09:24 +00:00
input {
oninput: move |evt: FormEvent| {
2023-09-01 20:38:55 +00:00
*current_route_str.write() = evt.value();
2023-05-24 00:09:24 +00:00
},
value: "{current_route_str}"
2023-05-24 00:09:24 +00:00
}
"dynamic: {dynamic}"
Link { to: Route::Route2 { user_id: 8888 }, "hello world link" }
Implement LiveView Router Integration (#1505) * Fix GoForwardButton calling can_go_back instead of can_go_forward * Add first draft of LiveviewHistory * Add external URL redirect * Lock evaluator channel outside loop * Add liveview to router examples * fixup! Add liveview to router examples * Communicate with liveview server on page load * Add PopState event to Liveview routing * Call updater callback from liveview history * Add rudimentary PopState functionality to liveview router. * Fix linter errors * Refactor * Fix navigator external redirection not working. * Add go back and go forward buttons to router examples * Finish functionality for timeline stack in liveview router * Add docs to LiveviewHistory * Replace Liveview history context attachment with constructor that takes context * Fix go forward/backward history/future shuffle * Support history across entire liveview session, if contiguous page jumps. * Remove unnecessary bounds * Add query and hash to location string * Run rustfmt * fix: Update server function docs link (#1489) * liveview: Add `interpreter_glue_relative_uri (#1481) * liveview: Add `interpreter_glue_relative_uri` By utilizing `window.location.host` in the client-side JavaScript, we can easily derive the WebSocket URI from a relative path URI. This approach obviates the need for host address retrieval on the server side, unlike the method of serving glue code in liveview using `interpreter_glue`. * liveview: Merge `.._relative_url` functionality - Merged `.._relative_url` to current API `interpreter_glue`. - Edit axum example to work with new feature. * liveview: Fix clippy warning * Rename modules to use snake_case (#1498) * Change Scope into &ScopeState * Move synchronization of state into router and make it opt-in --------- Co-authored-by: Marc Espín <mespinsanz@gmail.com> Co-authored-by: Seungwoo Kang <ki6080@gmail.com> Co-authored-by: Leonard <tigerros.gh@gmail.com> Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
2023-10-26 19:19:51 +00:00
button {
disabled: !navigator.can_go_back(),
onclick: move |_| {
navigator.go_back();
},
Implement LiveView Router Integration (#1505) * Fix GoForwardButton calling can_go_back instead of can_go_forward * Add first draft of LiveviewHistory * Add external URL redirect * Lock evaluator channel outside loop * Add liveview to router examples * fixup! Add liveview to router examples * Communicate with liveview server on page load * Add PopState event to Liveview routing * Call updater callback from liveview history * Add rudimentary PopState functionality to liveview router. * Fix linter errors * Refactor * Fix navigator external redirection not working. * Add go back and go forward buttons to router examples * Finish functionality for timeline stack in liveview router * Add docs to LiveviewHistory * Replace Liveview history context attachment with constructor that takes context * Fix go forward/backward history/future shuffle * Support history across entire liveview session, if contiguous page jumps. * Remove unnecessary bounds * Add query and hash to location string * Run rustfmt * fix: Update server function docs link (#1489) * liveview: Add `interpreter_glue_relative_uri (#1481) * liveview: Add `interpreter_glue_relative_uri` By utilizing `window.location.host` in the client-side JavaScript, we can easily derive the WebSocket URI from a relative path URI. This approach obviates the need for host address retrieval on the server side, unlike the method of serving glue code in liveview using `interpreter_glue`. * liveview: Merge `.._relative_url` functionality - Merged `.._relative_url` to current API `interpreter_glue`. - Edit axum example to work with new feature. * liveview: Fix clippy warning * Rename modules to use snake_case (#1498) * Change Scope into &ScopeState * Move synchronization of state into router and make it opt-in --------- Co-authored-by: Marc Espín <mespinsanz@gmail.com> Co-authored-by: Seungwoo Kang <ki6080@gmail.com> Co-authored-by: Leonard <tigerros.gh@gmail.com> Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
2023-10-26 19:19:51 +00:00
"go back"
}
button {
disabled: !navigator.can_go_forward(),
onclick: move |_| {
navigator.go_forward();
},
Implement LiveView Router Integration (#1505) * Fix GoForwardButton calling can_go_back instead of can_go_forward * Add first draft of LiveviewHistory * Add external URL redirect * Lock evaluator channel outside loop * Add liveview to router examples * fixup! Add liveview to router examples * Communicate with liveview server on page load * Add PopState event to Liveview routing * Call updater callback from liveview history * Add rudimentary PopState functionality to liveview router. * Fix linter errors * Refactor * Fix navigator external redirection not working. * Add go back and go forward buttons to router examples * Finish functionality for timeline stack in liveview router * Add docs to LiveviewHistory * Replace Liveview history context attachment with constructor that takes context * Fix go forward/backward history/future shuffle * Support history across entire liveview session, if contiguous page jumps. * Remove unnecessary bounds * Add query and hash to location string * Run rustfmt * fix: Update server function docs link (#1489) * liveview: Add `interpreter_glue_relative_uri (#1481) * liveview: Add `interpreter_glue_relative_uri` By utilizing `window.location.host` in the client-side JavaScript, we can easily derive the WebSocket URI from a relative path URI. This approach obviates the need for host address retrieval on the server side, unlike the method of serving glue code in liveview using `interpreter_glue`. * liveview: Merge `.._relative_url` functionality - Merged `.._relative_url` to current API `interpreter_glue`. - Edit axum example to work with new feature. * liveview: Fix clippy warning * Rename modules to use snake_case (#1498) * Change Scope into &ScopeState * Move synchronization of state into router and make it opt-in --------- Co-authored-by: Marc Espín <mespinsanz@gmail.com> Co-authored-by: Seungwoo Kang <ki6080@gmail.com> Co-authored-by: Leonard <tigerros.gh@gmail.com> Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
2023-10-26 19:19:51 +00:00
"go forward"
}
2023-05-31 22:12:52 +00:00
button {
onclick: move |_| {
navigator.push("https://www.google.com");
},
2023-05-31 22:12:52 +00:00
"google link"
}
2023-05-24 00:09:24 +00:00
p { "Site Map" }
pre { "{site_map:#?}" }
p { "Dynamic link" }
2023-07-14 18:40:38 +00:00
match parsed {
Ok(route) => {
if route != current_route {
2024-01-16 19:18:46 +00:00
rsx! {
2023-07-14 18:40:38 +00:00
Link {
2023-07-24 18:57:56 +00:00
to: route.clone(),
2023-07-14 18:40:38 +00:00
"{route}"
}
2023-05-24 00:09:24 +00:00
}
}
2023-07-14 18:40:38 +00:00
else {
Suspense boundaries/out of order streaming/anyhow like error handling (#2365) * create static site generation helpers in the router crate * work on integrating static site generation into fullstack * move ssg into a separate crate * integrate ssg with the launch builder * simplify ssg example * fix static_routes for child routes * move CLI hot reloading websocket code into dioxus-hot-reload * fix some unused imports * use the same hot reloading websocket code for fullstack * fix fullstack hot reloading * move cli hot reloading logic into the hot reload crate * ssg example working with dx serve * add more examples * fix clippy * switch to a result for Element * fix formatting * fix hot reload doctest imports * fix axum imports * add show method to error context * implement retaining nodes during suspense * fix unterminated if statements * communicate between tasks and suspense boundaries * make suspense placeholders easier to use * implement IntoDynNode and IntoVNode for more wrappers * fix clippy examples * fix rsx tests * add streaming html utilities to the ssr package * unify hydration and non-hydration ssr cache * fix router with Result Element * don't run server doc tests * Fix hot reload websocket doc examples * simple apps working with fullstack streaming * fix preloading wasm * Report errors encountered while streaming * remove async from incremental renderer * document new VirtualDom suspense methods * make streaming work with incremental rendering * fix static site generation * document suspense structs * create closure type; allow async event handlers in props; allow shorthand event handlers * test forwarding event handlers with the shorthand syntax * fix clippy * fix imports in spawn async doctest * fix empty rsx * fix async result event handlers * fix mounting router in multiple places * Fix task dead cancel race condition * simplify diffing before adding suspense * fix binary size increase * fix attribute diffing * more diffing fixes * create minimal fullstack feature * smaller fullstack bundles * allow mounting nodes that are already created and creating nodes without mounting them * fix hot reload feature * fix replacing components * don't reclaim virtual nodes * client side suspense working! * fix CLI * slightly smaller fullstack builds * fix multiple suspended scopes * fix merge errors * yield back to tokio every few polls to fix suspending on many tasks at once * remove logs * document suspense boundary and update suspense example * fix ssg * make streaming optional * fix some router and core tests * fix suspense example * fix serialization with out of order server futures * add incremental streaming hackernews demo * fix hackernews demo * fix root hackernews redirect * fix formatting * add tests for suspense cases * slightly smaller binaries * slightly smaller * improve error handling docs * fix errors example link * fix doc tests * remove log file * fix ssr cache type inference * remove index.html * fix ssg render template * fix assigning ids on elements with dynamic attributes * add desktop feature to the workspace examples * remove router static generation example; ssg lives in the dioxus-static-generation package * add a test for effects during suspense * only run effects on mounted nodes * fix multiple suspense roots * fix node iterator * fix closures without arguments * fix dioxus-core readme doctest * remove suspense logs * fix scope stack * fix clippy * remove unused suspense boundary from hackernews * assert that launch never returns for better compiler errors * fix static generation launch function * fix web renderer * pass context providers into server functions * add an example for FromContext * clean up DioxusRouterExt * fix server function context * fix fullstack desktop example * forward CLI serve settings to fullstack * re-export serve config at the root of fullstack * forward env directly instead of using a guard * just set the port in the CLI for fullstack playwright tests * fix fullstack dioxus-cli-config feature * fix launch server merge conflicts * fix fullstack launch context * Merge branch 'main' into suspense-2.0 * fix fullstack html data * remove drop virtual dom feature * add a comment about only_write_templates binary size workaround * remove explicit dependencies from use_server_future * make ErrorContext and SuspenseContext more similar * Tweak: small tweaks to tomls to make diff smaller * only rerun components under suspense after the initial placeholders are sent to the client * add module docs for suspense * keep track of when suspense boundaries are resolved * start implementing JS out of order streaming * fix core tests * implement the server side of suspense with js * fix streaming ssr with nested suspense * move streaming ssr code into fullstack * revert minification changes * serialize server future data as the html streams * start loading scripts wasm immediately instead of defering the script * very basic nested suspense example working with minimal html updates * clean up some suspense/error docs * fix hydrating nested pending server futures * sort resolved boundaries by height * Fix disconnecting clients while streaming * fix static generation crate * don't insert extra divs when hydrating streamed chunks * wait to swap in the elements until they are hydrated * remove inline streaming script * hackernews partially working * fix spa mode * banish the open shadow dom * fix removing placeholder * set up streaming playwright test * run web playwright tests on 9999 to avoid port conflicts with other local servers * remove suspense nodes if the suspense boundary is replaced before the suspense resolves on the server * ignore hydration of removed suspense boundaries * use path based indexing to fix hydrating suspense after parent suspense with child is removed * re-export dioxus error * remove resolved suspense divs if the suspense boundary has been removed * Fix client side initialized server futures * ignore comment nodes while traversing nodes in core to avoid lists getting swapped out with suspense * Pass initial hydration data to the client * hide pre nodes * don't panic if reclaiming an element fails * fix scope stack when polling tasks * improve deserialization out of length message * Ok(VNode::placeholder()) -> VNode::empty() * fix typo in rsx usage * restore testing changes from suspense example * clean up some logs and comments * fix playwright tests * clean up more changes in core * clean up core tests * remove anymap dependency * clean up changes to hooks * clean up changes in the router, rsx, and web * revert changes to axum-hello-world * fix use_server_future * fix clippy in dioxus-core * check that the next or previous node exist before checking if we should ignore them * fix formatting * fix suspense playwright test * remove unused suspense code * add more suspense playwright tests * add more docs for error boundaries * fix suspense core tests * fix ErrorBoundary example * remove a bunch of debug logging in js * fix router failure_external_navigation * use absolute paths in the interpreter build.rs * strip '\r' while hashing ts files * add a wrapper with a default error boundary and suspense boundary * restore hot reloading * ignore non-ts files when hashing * sort ts files before hashing them * fix rsx tests * fix fullstack doc tests * fix core tests * fix axum auth example * update suspense hydration diagram * longer playwright build limit * tiny fixes - spelling, formatting * update diagram link * remove comment and template nodes for suspense placeholders * remove comment nodes as we hydrate text * simplify hackernews example * clean up hydrating text nodes * switch to a separate environment variable for the base path for smaller binaries * clean up file system html trait * fix form data * move streaming code into fullstack * implement serialize and deserialize for CapturedError * remove waits in the nested suspense playwright spec * force sequential fullstack builds for CI * longer nested suspense delay for CI * fix --force-sequential flag * wait to launch server until client build is done --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
2024-07-02 03:50:36 +00:00
VNode::empty()
2023-07-14 18:40:38 +00:00
}
2023-05-24 00:09:24 +00:00
}
2023-07-14 18:40:38 +00:00
Err(err) => {
2024-01-16 19:18:46 +00:00
rsx! {
2023-07-14 18:40:38 +00:00
pre {
color: "red",
"Invalid route:\n{err}"
}
}
2023-05-24 00:39:18 +00:00
}
}
}
}
2023-05-24 00:09:24 +00:00
#[rustfmt::skip]
2023-06-01 16:03:44 +00:00
#[derive(Clone, Debug, PartialEq, Routable)]
2023-05-24 00:09:24 +00:00
enum Route {
2023-07-14 18:40:38 +00:00
#[nest("/test")]
// Nests with parameters have types taken from child routes
#[nest("/user/:user_id")]
// Everything inside the nest has the added parameter `user_id: usize`
// UserFrame is a layout component that will receive the `user_id: usize` parameter
#[layout(UserFrame)]
#[route("/:dynamic?:query")]
Route1 {
// The type is taken from the first instance of the dynamic parameter
user_id: usize,
dynamic: usize,
query: String,
},
#[route("/hello_world")]
// You can opt out of the layout by using the `!` prefix
#[layout(!UserFrame)]
Route2 { user_id: usize },
#[end_layout]
#[end_nest]
2023-05-24 00:09:24 +00:00
#[end_nest]
2023-05-31 17:11:11 +00:00
#[redirect("/:id/user", |id: usize| Route::Route3 { dynamic: id.to_string()})]
2023-05-31 18:57:33 +00:00
#[route("/:dynamic")]
2023-05-24 00:09:24 +00:00
Route3 { dynamic: String },
}