mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
Allow path
prop on <Route/>
to be any type that impl std::fmt::Display
This commit is contained in:
parent
6a4cbbf266
commit
263d5b1d89
3 changed files with 6 additions and 5 deletions
|
@ -10,12 +10,12 @@ use crate::{
|
||||||
/// Describes a portion of the nested layout of the app, specifying the route it should match,
|
/// 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.
|
/// the element it should display, and data that should be loaded alongside the route.
|
||||||
#[component(transparent)]
|
#[component(transparent)]
|
||||||
pub fn Route<E, F>(
|
pub fn Route<E, F, P>(
|
||||||
cx: Scope,
|
cx: Scope,
|
||||||
/// The path fragment that this route should match. This can be static (`users`),
|
/// 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
|
/// include a parameter (`:id`) or an optional parameter (`:id?`), or match a
|
||||||
/// wildcard (`user/*any`).
|
/// wildcard (`user/*any`).
|
||||||
path: &'static str,
|
path: P,
|
||||||
/// The view that should be shown when this route is matched. This can be any function
|
/// 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, <p>"Show this"</p> })`
|
/// that takes a [Scope] and returns an [Element] (like `|cx| view! { cx, <p>"Show this"</p> })`
|
||||||
/// or `|cx| view! { cx, <MyComponent/>` } or even, for a component with no props, `MyComponent`).
|
/// or `|cx| view! { cx, <MyComponent/>` } or even, for a component with no props, `MyComponent`).
|
||||||
|
@ -27,6 +27,7 @@ pub fn Route<E, F>(
|
||||||
where
|
where
|
||||||
E: IntoView,
|
E: IntoView,
|
||||||
F: Fn(Scope) -> E + 'static,
|
F: Fn(Scope) -> E + 'static,
|
||||||
|
P: std::fmt::Display,
|
||||||
{
|
{
|
||||||
let children = children
|
let children = children
|
||||||
.map(|children| {
|
.map(|children| {
|
||||||
|
@ -43,7 +44,7 @@ where
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
RouteDefinition {
|
RouteDefinition {
|
||||||
path,
|
path: path.to_string(),
|
||||||
children,
|
children,
|
||||||
view: Rc::new(move |cx| view(cx).into_view(cx)),
|
view: Rc::new(move |cx| view(cx).into_view(cx)),
|
||||||
}
|
}
|
||||||
|
|
|
@ -273,7 +273,7 @@ fn create_routes(route_def: &RouteDefinition, base: &str) -> Vec<RouteData> {
|
||||||
let RouteDefinition { children, .. } = route_def;
|
let RouteDefinition { children, .. } = route_def;
|
||||||
let is_leaf = children.is_empty();
|
let is_leaf = children.is_empty();
|
||||||
let mut acc = Vec::new();
|
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 path = join_paths(base, &original_path);
|
||||||
let pattern = if is_leaf {
|
let pattern = if is_leaf {
|
||||||
path
|
path
|
||||||
|
|
|
@ -5,7 +5,7 @@ use leptos::*;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct RouteDefinition {
|
pub struct RouteDefinition {
|
||||||
pub path: &'static str,
|
pub path: String,
|
||||||
pub children: Vec<RouteDefinition>,
|
pub children: Vec<RouteDefinition>,
|
||||||
pub view: Rc<dyn Fn(Scope) -> View>,
|
pub view: Rc<dyn Fn(Scope) -> View>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue