Search params in loader (unclear part of the documentation)
Hi, I'm reading the documentation related to the rationale for not having search params directly available in the loader and I'm not sure I understand the rationale 😅: https://tanstack.com/router/v1/docs/framework/react/guide/data-loading#using-search-params-in-loaders
Assuming the router scopes each request based on pathname + search params, in what case would using search params (vs different route segments) cause the issues described in the section?
-----
For example this section:
For example, you might ask your /posts route to preload page 2's results, but without the distinction of pages in your route configuration, you will end up fetching, storing and displaying page 2's data on your /posts or ?page=1 screen instead of it preloading in the background!It's unclear to me why I would end up storing page's 2 data in page 1s? Since route /posts?page=1 and /posts?page=2 are different and therefore I'd expect them to be stored differently?
4 Replies
eager-peach•9mo ago
they would only be stored differently if you tell router that the
page
search param is a dependency of the loader
wise-whiteOP•9mo ago
Just out of curiosity: why isn't this the default behaviour?
eager-peach•9mo ago
because you might have search params that are NOT dependencies of the loader
so either you need to opt-in or opt-out
wise-whiteOP•9mo ago
Right. It just seems weird that we don't have "search params are dependencies of the loader" by default. I think it might make more sense to have that default and then optionally opt out.
URL pathname + search name identifies a unique resource in pretty much every single aspect of the HTTP protocol (see e.g. caching).