mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 14:54:16 +00:00
Merge pull request #780 from leptos-rs/warn-on-routes-issues
docs: warn if you put something invalid inside `<Routes/>`
This commit is contained in:
commit
952646f066
2 changed files with 32 additions and 15 deletions
|
@ -28,19 +28,7 @@ pub fn RouterExample(cx: Scope) -> impl IntoView {
|
||||||
</nav>
|
</nav>
|
||||||
<main>
|
<main>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route
|
<ContactRoutes/>
|
||||||
path=""
|
|
||||||
view=move |cx| view! { cx, <ContactList/> }
|
|
||||||
>
|
|
||||||
<Route
|
|
||||||
path=":id"
|
|
||||||
view=move |cx| view! { cx, <Contact/> }
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path="/"
|
|
||||||
view=move |_| view! { cx, <p>"Select a contact."</p> }
|
|
||||||
/>
|
|
||||||
</Route>
|
|
||||||
<Route
|
<Route
|
||||||
path="about"
|
path="about"
|
||||||
view=move |cx| view! { cx, <About/> }
|
view=move |cx| view! { cx, <About/> }
|
||||||
|
@ -59,6 +47,27 @@ pub fn RouterExample(cx: Scope) -> impl IntoView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// You can define other routes in their own component.
|
||||||
|
// Use a #[component(transparent)] that returns a <Route/>.
|
||||||
|
#[component(transparent)]
|
||||||
|
pub fn ContactRoutes(cx: Scope) -> impl IntoView {
|
||||||
|
view! { cx,
|
||||||
|
<Route
|
||||||
|
path=""
|
||||||
|
view=move |cx| view! { cx, <ContactList/> }
|
||||||
|
>
|
||||||
|
<Route
|
||||||
|
path=":id"
|
||||||
|
view=move |cx| view! { cx, <Contact/> }
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path="/"
|
||||||
|
view=move |_| view! { cx, <p>"Select a contact."</p> }
|
||||||
|
/>
|
||||||
|
</Route>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn ContactList(cx: Scope) -> impl IntoView {
|
pub fn ContactList(cx: Scope) -> impl IntoView {
|
||||||
log::debug!("rendering <ContactList/>");
|
log::debug!("rendering <ContactList/>");
|
||||||
|
|
|
@ -32,9 +32,17 @@ pub fn Routes(
|
||||||
.as_children()
|
.as_children()
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|child| {
|
.filter_map(|child| {
|
||||||
child
|
let def = child
|
||||||
.as_transparent()
|
.as_transparent()
|
||||||
.and_then(|t| t.downcast_ref::<RouteDefinition>())
|
.and_then(|t| t.downcast_ref::<RouteDefinition>());
|
||||||
|
if def.is_none() {
|
||||||
|
warn!(
|
||||||
|
"[NOTE] The <Routes/> component should include *only* \
|
||||||
|
<Route/>or <ProtectedRoute/> components, or some \
|
||||||
|
#[component(transparent)] that returns a RouteDefinition."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
def
|
||||||
})
|
})
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
Loading…
Reference in a new issue