Files
dioxus/packages/playwright-tests/web-hash-routing/src/main.rs
T
Moritz HedtkeandJonathan Kelley 2be2333ef4 Add initial version of hash history (#4311)
* Add initial version of hash history

* wip...

* more cleanups

* cleanup the web history impl and then add a playwright test

---------

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
2025-06-24 11:50:03 -07:00

62 lines
1.1 KiB
Rust

use std::rc::Rc;
use dioxus::{prelude::*, web::HashHistory};
fn main() {
dioxus::LaunchBuilder::new()
.with_cfg(dioxus::web::Config::new().history(Rc::new(HashHistory::new(false))))
.launch(|| {
rsx! {
Router::<Route> {}
}
})
}
#[derive(Routable, Clone, PartialEq)]
#[rustfmt::skip]
enum Route {
#[redirect("/",|| Route::Other)]
#[route("/other")]
Other,
#[route("/other/:id")]
OtherId { id: String },
#[route("/:..segments")]
NotFound { segments: Vec<String> },
}
#[component]
fn Other() -> Element {
rsx! {
div {
id: "other",
"Other"
}
Link {
id: "other-id-link",
to: Route::OtherId { id: "123".to_string() },
"go to OtherId"
}
}
}
#[component]
fn OtherId(id: String) -> Element {
rsx! {
div {
id: "other-id",
"OtherId {id}"
}
}
}
#[component]
fn NotFound(segments: Vec<String>) -> Element {
rsx! {
div {
id: "not-found",
"NotFound {segments:?}"
}
}
}