Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Allow loaders in nested routes to reach into data called by parent/ancestor routes #9527

Closed
dbhoang opened this issue Oct 31, 2022 · 1 comment
Labels

Comments

@dbhoang
Copy link

dbhoang commented Oct 31, 2022

What is the new or updated feature that you are suggesting?

Current behavior for nested loaders in data routers have all loaders firing at once when visiting a route. For example:

const router = createBrowserRouter(
  createRoutesFromElements(
    <Route path="/" element={<DataLayout />}>
      <Route path="animals/*" element={<Animals />} loader={animalsLoader} id="animals">
         <Route path=":animalId">
          <Route path="dog" element={<Dog />} loader={dogLoader} />
          <Route path="cat" element={<Cat />} />
        </Route>
      </Route>
    </Route>
  )
)

I have the above router. When you visit /animals/1/dog, the animalsLoader and dogLoader are called at the same time. I'm hoping that we can call these loaders sequentially and allow dogLoader to use information from animalLoader's data.

Why should this feature be included?

If we make this a less trivial example, suppose any nested route under animals calls auth and fetches user information to view any nested route under it. And there's a non-trivial amount of routes under animals. Allowing for sequential loader calls, let's us perform this action easily.

@timdorr
Copy link
Member

timdorr commented Oct 31, 2022

#9188 (comment)

@timdorr timdorr closed this as completed Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants