-
UPDATE: it turns out the issue is different from my initial framing. I've updated the title to reflect that. The below code panics at the use leptos::prelude::*;
use leptos_router::components::{Outlet, ParentRoute, Route, Router, Routes};
use leptos_router::path;
#[derive(Clone)]
struct TheContext;
#[component]
pub fn Parent() -> impl IntoView {
provide_context(TheContext);
view! { <Outlet /> }
}
#[component]
pub fn Child() -> impl IntoView {
use_context::<TheContext>().expect("TheContext not provided.");
}
#[component]
pub fn App() -> impl IntoView {
view! {
<Router>
<Routes fallback=|| ()>
<ParentRoute path=path!("/") view=|| Parent > // Doing `view=Parent` instead avoids the panic!
<Route path=path!("") view=Child />
</ParentRoute>
</Routes>
</Router>
}
} I haven't articulated in this minimal repro why I want this sort of function nesting. I am trying to work around this issue by avoiding the need for the function nesting. But I thought it'd be good to update this issue with what actually was my issue to provide some closure (pun intended haha). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The answer is via context, and if context isn't working then more details are helpful. |
Beta Was this translation helpful? Give feedback.
The answer is via context, and if context isn't working then more details are helpful.