Replies: 3 comments 2 replies
-
I don't think your You could, for example, have a Essentially, what I'm suggesting is that all of the functionality of your <Router>
<main>
<Routes>
<ParentRoute path=StaticSegment("") view=AppProvider>
<Route path=StaticSegment("/home" view=Home>
<Route path=StaticSegment("/settings" view=Settings>
// ...
</ParentRoute>
</Routes>
</main>
</Router> |
Beta Was this translation helpful? Give feedback.
-
I believe I would move your AppProvider inside the FlatRoutes component, but overall this structure should work. Assuming your |
Beta Was this translation helpful? Give feedback.
-
So I tried to do the ParentRoute/Context approach but ran into a number of other issues with Context not passing through for Thaw and the Router. Things like use_location inside the Header component stopped reactively updating on navigation, and the RoutingProgress stopped working. I wasn't able to figure out how to solve it even using the outer_owner.with approach. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm not sure if this is an anti-pattern or if there's a way to get this to work. I need to create some global context signals that rely on resources from server functions. Those server functions require context from the root object that sets up the leptos routes because in addition to spawning a web server, it spawns some background threads that handle messaging and status updates from other services.
I need to share these resources across routes for dynamic updates.
Basically I have the following routes and HTML structure:
Where AppProvider would provide some context - which includes some Resources for data requiring the service context from the router. It also includes some actions, one of which is a FormData for file uploads that requires Action::new_local which will refetch these resources.
However, this doesn't work because AppProvider is outside of a given route, and apparently the context only exists under a Route component.
So what I've been trying to do is conditionally get the context - if it exists and is Some, return it, otherwise create it and provide it. This mostly works, but then I get dispose errors when trying to navigate and I sometimes get SendWrapper panics (because of the local action) when refreshing the page.
The reason this state needs to be higher up is because the Header needs access to some of it. I also tried removing the dependency from the Header by using a Portal - but so far I still have issues.
Is there any other way to inject state/context into the root of the app? These resources should live for the entire lifecycle of an app session, regardless of route. Or if there's another way to handle the data flow, I'm open - This structure was originally implemented in a React app and migrating is proving a bit painful since certain patterns don't work the same
Beta Was this translation helpful? Give feedback.
All reactions