T
TanStack2w ago
fascinating-indigo

Control `shouldReload` from navigate

In my app, I need that if a user is already on a route, clicking on a button or in general triggering a navigation towards that same route won't do anything (no pending component, no loader re-run). I did that by setting to false the shouldReload property on the createFileRoute call (bonus related question: is there a way to set it on the root route, like defaultShouldReload instead of repeating on every route?). This approach works just fine, but now I need to handle the user log in. After a successful login, I need to reload the current route, but doing that using navigate({ to: "." }) won't trigger the loader, because of shouldReload=false. Is there a way to "tell" the navigate function to use a different value for shouldReload? Or, is there a way to use a function for shouldReload which could recognize such situations? The only way I currently found is to add a piece of global state which changes before and after logging in and use it in loaderDeps, but that's pretty ugly and overkill to me. Thanks in advance and have a good day :cattosip:
2 Replies
frozen-sapphire
frozen-sapphire2w ago
shouldReload can be a function, yes. putting this on a navigate call does not make much sense IMO as this would be a value for all(?) matched routes and not specific ones usually you handle those cases by invalidating those routes and reloading
fascinating-indigo
fascinating-indigoOP2w ago
Awesome, I resolved my problem by adding router.invalidate() after login-s and logout-s. Thank you very much :hugheart:

Did you find this page helpful?