TanStackT
TanStack5mo ago
4 replies
rubber-blue

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:
Was this page helpful?