Hi everyone,
I'm working on a routing setup and need some guidance on the best way to handle a redirect after fetching data. Here's my scenario:
- I have two routes:
/usersand/users/$userId - The purpose of the
/usersroute is to redirect to/users/$userIdfor the first user fetched from my backend. - I've attempted to use
throw redirect()in the loader, but it's not working as expected due to preloading.
Here's what I'm trying to achieve:
- When a user visits
/users, the app should fetch the first user from the backend. - Then, it should immediately redirect to
/users/$userIdwhere$userIdis the ID of the first user fetched.
I'd appreciate any suggestions on how to implement this efficiently and correctly. Are there any best practices or specific methods I should be using for this kind of redirect after a fetch? Should I do in the component ?
Thanks in advance for your help!