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

Fetcher loads from _layout instead of _index route #116

Closed
t-animal opened this issue Apr 17, 2024 · 2 comments
Closed

Fetcher loads from _layout instead of _index route #116

t-animal opened this issue Apr 17, 2024 · 2 comments

Comments

@t-animal
Copy link

In a setup with a projects+/_layout.tsx with a loader-function and a projects+/_index.tsx with a loader function, a fetcher uses the loader from the _layout-file instead of the _index-file.

I could fix the issue by appending ?index to the url:

const loadMore = () => {
    fetcher.load(`${location.pathname}?index&page=${page}`); // without this ?index fetcher loads from the loader located at _layout.tsx
  };

after I stumbled on #14 . I first thought I had overlooked something, but either this is undocumented or a bug. Since the behavior seems to have been fixed in #14 I guess it's a bug.

@t-animal
Copy link
Author

@kiliman
Copy link
Owner

kiliman commented Apr 18, 2024

Yes, since the /projects URL matches both the layout and the index route, you must specify which one you prefer by including the ?index query param for the index route.

This is needed because fetcher.load requests data from a specific route, unlike navigations, where Remix will fetch all matching route loaders.

The Remix docs mention the ?index query param, but only in the context of Form posts. They should be updated to also include fetchers.

https://remix.run/docs/en/main/guides/index-query-param

As for #14, it was a bug in Remix with how it handled index routes, but that was from a very old version. The way it works now is correct and by design.

@kiliman kiliman closed this as completed Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants