Parse redirects in the same order they appear in (#2650)

* Parse redirects in the same order they appear in
This commit is contained in:
Evan Almloff authored and GitHub committed 2024-07-25 17:47:38 -07:00
1 parent c6a2e5b6c8
commit 443b9a4af6
4 files changed
+120 -51

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
mod link;
mod outlet;
mod redirect;
mod without_index;
+42
View File
@@ -0,0 +1,42 @@
use dioxus::prelude::*;
use std::str::FromStr;
// Tests for regressions of <https://github.com/DioxusLabs/dioxus/issues/2549>
#[test]
fn redirects_apply_in_order() {
let path = Route::from_str("/").unwrap();
assert_eq!(
path,
Route::Home {
lang: "en".to_string()
}
);
let mut vdom = VirtualDom::new_with_props(App, AppProps { path });
vdom.rebuild_in_place();
let as_string = dioxus_ssr::render(&vdom);
assert_eq!(as_string, "en");
}
#[derive(Clone, Routable, Debug, PartialEq)]
enum Route {
// The redirect should try to parse first because it is placed first in the enum
#[redirect("/", || Route::Home { lang: "en".to_string() })]
#[route("/?:lang")]
Home { lang: String },
}
#[component]
fn Home(lang: String) -> Element {
rsx! { "{lang}" }
}
#[component]
fn App(path: Route) -> Element {
rsx! {
Router::<Route> {
config: {
move |_| RouterConfig::default().history(MemoryHistory::with_initial_path(path.clone()))
}
}
}
}