I’m working on a React Native app using Expo Router. I’m trying to navigate between screens and pass parameters such as bar_id
, table_id
, and user_id
via URL query parameters, but they are not being passed correctly. The parameters table_id
and user_id
are undefined when received on the target screen, even though I am sure I’m passing them.
Here’s how I’m navigating to the next screen:
router.push({
pathname: '/client/scan/InviteClientsScreen',
query: { bar_id, table_id, user_id }
});
However, when I try to access the parameters in the target screen using useLocalSearchParams(), I receive undefined for table_id and user_id:
const { bar_id, table_id, user_id } = useLocalSearchParams();
console.log({ bar_id, table_id, user_id });
I’ve also logged the parameters before navigation and confirmed that they are being set correctly, but for some reason, they're coming through as undefined when received.
I've tried the following solutions, but they didn’t work:
1. Using params instead of query for navigation.
2. Adding fallback values like { table_id: 'default' } when parameters are undefined.
3. Ensuring that the parameters are not being overwritten before navigation.
Why am I receiving undefined for table_id and user_id?
Is there something wrong with how I'm passing parameters, or is this an issue with how expo-router handles URL query parameters?
Any suggestions on how to troubleshoot this or best practices for passing parameters in Expo Router?
I've logged the parameters before navigation, and they are set correctly.
The only parameter that seems to work is bar_id. Is this an issue with useLocalSearchParams()?
Thanks for any help!
2
Answers
I dont know if it should be done like this, but that’s how i do it.
Screen that passes the params :
Screen that params were passed to
Also, the screen that params are being passed to is named [editId].js, I don’t know if that helps with something if it comes to passing params, but I though that maybe it’s important to mention.
only change the
query
toparams
and you can access the parameters here