diff --git a/integrations/axum/Cargo.toml b/integrations/axum/Cargo.toml index f9351ff76f..d1fac2d9bd 100644 --- a/integrations/axum/Cargo.toml +++ b/integrations/axum/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/leptos-rs/leptos" description = "Axum integrations for the Leptos web framework." [dependencies] -axum = { version = "0.6", default-features = false } +axum = { version = "0.6", default-features = false, features=["matched-path"] } futures = "0.3" http = "0.2.8" hyper = "0.14.23" diff --git a/integrations/axum/src/lib.rs b/integrations/axum/src/lib.rs index f28963f697..56e60e90c7 100644 --- a/integrations/axum/src/lib.rs +++ b/integrations/axum/src/lib.rs @@ -7,7 +7,7 @@ use axum::{ body::{Body, Bytes, Full, StreamBody}, - extract::{FromRef, FromRequestParts, Path, RawQuery}, + extract::{FromRef, FromRequestParts, MatchedPath, Path, RawQuery}, http::{ header::{HeaderName, HeaderValue}, HeaderMap, Request, StatusCode, @@ -644,17 +644,22 @@ where ); move |req| { - let uri = req.uri(); // 1. Process route to match the values in routeListing - let path = uri.path(); + let path = req + .extensions() + .get::() + .expect("Failed to get Axum router rule") + .as_str(); // 2. Find RouteListing in paths. This should probably be optimized, we probably don't want to // search for this every time let listing: &RouteListing = - paths.iter().find(|r| r.path() == path).expect( - "Failed to find the route {path} requested by the user. This \ - suggests that the routing rules in the Router that call this \ - handler needs to be edited!", - ); + paths.iter().find(|r| r.path() == path).unwrap_or_else(|| { + panic!( + "Failed to find the route {path} requested by the user. \ + This suggests that the routing rules in the Router that \ + call this handler needs to be edited!" + ) + }); // 3. Match listing mode against known, and choose function match listing.mode() { SsrMode::OutOfOrder => ooo(req),