diff --git a/integrations/actix/src/lib.rs b/integrations/actix/src/lib.rs index 0907b5caa..c60642296 100644 --- a/integrations/actix/src/lib.rs +++ b/integrations/actix/src/lib.rs @@ -1215,13 +1215,18 @@ where let mode = listing.mode(); for method in listing.methods() { + let additional_context = additional_context.clone(); + let additional_context_and_method = move || { + provide_context(method); + additional_context(); + }; router = if let Some(static_mode) = listing.static_mode() { router.route( path, static_route( options.clone(), app_fn.clone(), - additional_context.clone(), + additional_context_and_method.clone(), method, static_mode, ), @@ -1233,7 +1238,7 @@ where SsrMode::OutOfOrder => { render_app_to_stream_with_context( options.clone(), - additional_context.clone(), + additional_context_and_method.clone(), app_fn.clone(), method, ) @@ -1241,7 +1246,7 @@ where SsrMode::PartiallyBlocked => { render_app_to_stream_with_context_and_replace_blocks( options.clone(), - additional_context.clone(), + additional_context_and_method.clone(), app_fn.clone(), method, true, @@ -1250,14 +1255,14 @@ where SsrMode::InOrder => { render_app_to_stream_in_order_with_context( options.clone(), - additional_context.clone(), + additional_context_and_method.clone(), app_fn.clone(), method, ) } SsrMode::Async => render_app_async_with_context( options.clone(), - additional_context.clone(), + additional_context_and_method.clone(), app_fn.clone(), method, ), diff --git a/integrations/axum/src/lib.rs b/integrations/axum/src/lib.rs index a64729b39..42d69fdd0 100644 --- a/integrations/axum/src/lib.rs +++ b/integrations/axum/src/lib.rs @@ -1615,6 +1615,11 @@ where let path = listing.path(); for method in listing.methods() { + let cx_with_state = cx_with_state.clone(); + let cx_with_state_and_method = move || { + provide_context(method); + cx_with_state(); + }; router = if let Some(static_mode) = listing.static_mode() { #[cfg(feature = "default")] { @@ -1623,7 +1628,7 @@ where path, LeptosOptions::from_ref(options), app_fn.clone(), - cx_with_state.clone(), + cx_with_state_and_method.clone(), method, static_mode, ) @@ -1643,7 +1648,7 @@ where SsrMode::OutOfOrder => { let s = render_app_to_stream_with_context( LeptosOptions::from_ref(options), - cx_with_state.clone(), + cx_with_state_and_method.clone(), app_fn.clone(), ); match method { @@ -1657,7 +1662,7 @@ where SsrMode::PartiallyBlocked => { let s = render_app_to_stream_with_context_and_replace_blocks( LeptosOptions::from_ref(options), - cx_with_state.clone(), + cx_with_state_and_method.clone(), app_fn.clone(), true ); @@ -1672,7 +1677,7 @@ where SsrMode::InOrder => { let s = render_app_to_stream_in_order_with_context( LeptosOptions::from_ref(options), - cx_with_state.clone(), + cx_with_state_and_method.clone(), app_fn.clone(), ); match method { @@ -1686,7 +1691,7 @@ where SsrMode::Async => { let s = render_app_async_with_context( LeptosOptions::from_ref(options), - cx_with_state.clone(), + cx_with_state_and_method.clone(), app_fn.clone(), ); match method { diff --git a/router/src/components/route.rs b/router/src/components/route.rs index 369cada01..a43bc7e7c 100644 --- a/router/src/components/route.rs +++ b/router/src/components/route.rs @@ -410,6 +410,11 @@ impl RouteContext { pub fn outlet(&self) -> impl IntoView { (self.inner.outlet)() } + + /// The http method used to navigate to this route. Defaults to [`Method::Get`] when unavailable like in client side routing + pub fn method(&self) -> Method { + use_context().unwrap_or_default() + } } pub(crate) struct RouteContextInner {