diff --git a/router/src/components/route.rs b/router/src/components/route.rs index 2eb7e88fd..05776e5da 100644 --- a/router/src/components/route.rs +++ b/router/src/components/route.rs @@ -10,12 +10,12 @@ use crate::{ /// Describes a portion of the nested layout of the app, specifying the route it should match, /// the element it should display, and data that should be loaded alongside the route. #[component(transparent)] -pub fn Route( +pub fn Route( cx: Scope, /// The path fragment that this route should match. This can be static (`users`), /// include a parameter (`:id`) or an optional parameter (`:id?`), or match a /// wildcard (`user/*any`). - path: &'static str, + path: P, /// The view that should be shown when this route is matched. This can be any function /// that takes a [Scope] and returns an [Element] (like `|cx| view! { cx,

"Show this"

})` /// or `|cx| view! { cx, ` } or even, for a component with no props, `MyComponent`). @@ -27,6 +27,7 @@ pub fn Route( where E: IntoView, F: Fn(Scope) -> E + 'static, + P: std::fmt::Display, { let children = children .map(|children| { @@ -43,7 +44,7 @@ where }) .unwrap_or_default(); RouteDefinition { - path, + path: path.to_string(), children, view: Rc::new(move |cx| view(cx).into_view(cx)), } diff --git a/router/src/components/routes.rs b/router/src/components/routes.rs index 725d1db96..db1d7f6f8 100644 --- a/router/src/components/routes.rs +++ b/router/src/components/routes.rs @@ -273,7 +273,7 @@ fn create_routes(route_def: &RouteDefinition, base: &str) -> Vec { let RouteDefinition { children, .. } = route_def; let is_leaf = children.is_empty(); let mut acc = Vec::new(); - for original_path in expand_optionals(route_def.path) { + for original_path in expand_optionals(&route_def.path) { let path = join_paths(base, &original_path); let pattern = if is_leaf { path diff --git a/router/src/matching/route.rs b/router/src/matching/route.rs index 9769a9e27..33d222fff 100644 --- a/router/src/matching/route.rs +++ b/router/src/matching/route.rs @@ -5,7 +5,7 @@ use leptos::*; #[derive(Clone)] pub struct RouteDefinition { - pub path: &'static str, + pub path: String, pub children: Vec, pub view: Rc View>, }