provide params properly in FlatRouter

This commit is contained in:
Greg Johnston 2024-04-27 13:50:44 -04:00
parent 53b22a9b74
commit 420dccda60
5 changed files with 12 additions and 8 deletions

View File

@ -1,6 +0,0 @@
[unstable]
build-std = ["std", "panic_abort", "core", "alloc"]
build-std-features = ["panic_immediate_abort"]
[build]
target = "aarch64-apple-darwin"

View File

@ -10,7 +10,7 @@ crate-type = ["cdylib", "rlib"]
console_error_panic_hook = "0.1"
console_log = "1"
lazy_static = "1"
leptos = { path = "../../leptos", features = ["nightly", "hydration"] }
leptos = { path = "../../leptos", features = ["hydration" ] } #"nightly", "hydration"] }
leptos_meta = { path = "../../meta" }
leptos_axum = { path = "../../integrations/axum", optional = true }
leptos_router = { path = "../../router" }

View File

@ -0,0 +1,2 @@
[toolchain]
channel = "stable" # test change

View File

@ -5,6 +5,7 @@ use crate::{
State, Url,
},
navigate::{NavigateOptions, UseNavigate},
params::ParamsMap,
resolve_path::resolve_path,
FlatRoutesView, MatchNestedRoutes, NestedRoute, NestedRoutesView, Routes,
SsrMode,
@ -267,11 +268,13 @@ where
});
let outer_owner =
Owner::current().expect("creating Router, but no Owner was found");
let params = ArcRwSignal::new(ParamsMap::new());
move || FlatRoutesView {
routes: routes.clone(),
path: path.clone(),
fallback: fallback(),
outer_owner: outer_owner.clone(),
params: params.clone(),
}
}

View File

@ -41,6 +41,7 @@ pub(crate) struct FlatRoutesView<Defs, Fal, R> {
pub path: ArcMemo<String>,
pub fallback: Fal,
pub outer_owner: Owner,
pub params: ArcRwSignal<ParamsMap>,
}
impl<Defs, Fal, R> FlatRoutesView<Defs, Fal, R>
@ -57,14 +58,18 @@ where
path,
fallback,
outer_owner,
params,
} = self;
outer_owner.with(|| {
provide_context(params.clone().read_only());
let new_match = routes.match_route(&path.read());
match new_match {
None => Either::Left(fallback),
Some(matched) => {
let params = matched.to_params();
let new_params =
matched.to_params().into_iter().collect::<ParamsMap>();
params.set(new_params);
let (view, child) = matched.into_view_and_child();
#[cfg(debug_assertions)]