Problem with Dynamic routing and useQuery
Answered
Southern fire ant posted this in #help-forum
Southern fire antOP
I have a Nextjs app with 2 static routes, respectively locations and characters. Inside this you can find links that redirect to 2 dynamic routes, location/[lid].tsx and character/[cid].tsx.
In my project I am using tanstack useQuery
Here's my problem: if I access character/[cid].tsx first, and then navigate through the app and access location/[lid].tsx, the second page's useQuery *data *object will have the value that was fetched in the first page. This is causing some errors in my application, beacuse I'm trying to access properties that are not actually there.
This problem also happens in reverse; it's like if Next thinks the 2 routes are the same.
In my project I am using tanstack useQuery
Here's my problem: if I access character/[cid].tsx first, and then navigate through the app and access location/[lid].tsx, the second page's useQuery *data *object will have the value that was fetched in the first page. This is causing some errors in my application, beacuse I'm trying to access properties that are not actually there.
This problem also happens in reverse; it's like if Next thinks the 2 routes are the same.
Answered by Southern fire ant
Ok, I actually forgot to update the useQuery keys... my bad. That caused the issue
1 Reply
Southern fire antOP
Ok, I actually forgot to update the useQuery keys... my bad. That caused the issue
Answer