Replies: 2 comments 2 replies
-
By default, Remix will only call parent loaders if the new route is not a child route. That is, common ancestors like root and parent layout are not called again since Remix already has the data in context. Mutations will trigger Remix to revalidate all active loaders. Since clicking a menu isn't a mutation, and if you're navigating to a sibling route, then the parent loader is not fetched again. This is where you can force Remix to revalidate imperatively via the |
Beta Was this translation helpful? Give feedback.
-
Thank you for your suggestion. I understand that by default, Remix optimizes data fetching by not recalling loaders for parent or common ancestor routes when navigating to a child or sibling route, unless there's a mutation that triggers a revalidation of all active loaders. Your mention of the I've been considering an alternative approach using However, I'm curious if there's a more idiomatic or streamlined way within Remix to handle this scenario. Specifically, I'm looking for a solution that aligns with Remix's architecture and design principles, ideally minimizing manual interventions and leveraging Remix's built-in mechanisms for data fetching and state management. Does Remix offer a more elegant solution for dynamically updating data in response to navigation actions, especially for cases like submenu loading in a shared layout component? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm working with Remix to develop an application that includes a layout with a main menu. My goal is to dynamically load submenu items based on the route a user selects from the main menu. I'm using a
NavLink
component for menu items, and a loader function to check the current URL pathname. Based on this pathname, the loader determines if the selected menu item has an associated submenu and sends this data back to the client component to render it.However, I've encountered a problem where the layout component only re-renders under two specific conditions: either when a user clicks the same navigation URL again or when the browser is reloaded. If the user navigates to a different route via the menu, the layout does not re-render, and consequently, the submenu does not update based on the loader's data for the new route.
I understand that I might be able to manage this scenario with a function triggered by the
NavLink
to force a re-render, but I'm seeking a more straightforward way to handle this within Remix's architecture.I'm looking for guidance on how to properly manage this scenario in Remix. Specifically, I'd like to understand:
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions