Calling API and updating search params before loading a route
Hi, I have a case where BEFORE loading a route I'd really like to make some API call to check something and then update the searchParams based on the result.
Something like: click -> see loading -> API call in the background -> searchparams update -> route is loaded
What's the best way to achieve that? I tried beforeLoad for context update, but in middleware I only have access to the search params and not to context
3 Replies
sensitive-blue•9mo ago
beforeLoad is the answer. throw a redirect to update search params
flat-fuchsiaOP•9mo ago
That's what I try:
and unfortunately I get into infinite loop - see gazillion of console.logs with data. What am I doing wrong?
OK, I just need to check whether
user_id is already set at the beginning of the beforeLoad 😅
sensitive-blue•9mo ago
yep