In the Ionic/React app, the param passed by page A using component got picked up in page B, but only when running in web browser. In the emulator the param value is “undefined”.
But If I run on a web browser first, then when running the app on emulator, the param value shows up.
How is the param value (itemId in page A) getting set? Is the link actually set and the param value is incorrect, or is the link not set, causing the param value to be incorrect?
Hi @ptmkenny the item Id is from a previous API call, it shows in the sending page already. For example, in that page it is render as a table with column as Item ID, and the row is aa, bb, cc, …So you can see the values (aa, bb, cc…) are there. The value is used in the Link component to go to the ItemDetail page.
At debugging, in web browser the itemId has value in the detail page. But absent in the emulator, when I debug with the Chrome devtool.
Please feel free to ask for any clarification. Thank you.
That is correct. As I debug along the break points, it goes to the ItemDetail and after the line of
const { itemId } = useParams() the itemId is still undefined. But when run in a web browser, itemId has a correct value.
This behavior is similar to this issue But I can not apply the Switch tag to Ionic/React router, as that solution implies.
The issue you linked does look similar, and if you don’t have a <Switch>, you need one. I am using basically the same structure as the linked issue in my app. <Switch> is wrapped in a suspense component because I use Tanstack Query suspense queries to load some heavy pages, but the code in the linked issue looks correct to me as well.
When I enter the path and parameter directly in the Chrome Devtools, the parameter shows up and show expected detail. So it does look like a router issue. But I got stuck still because the Switch tag causes a white screen. I wondered if it is compatible. But you can have it without a problem, apparently.
What happens if you remove all the stuff that isn’t part of the router, like <IonSplitPane> from the router so you just have IonReactRouter -> IonRouterOutlet -> Switch`?
Try making the child component of a <Route> an <IonPage>. Your wrapper component may be incorrectly set up. If you’re still having trouble, I would check one of the Ionic demo apps that already has routing set up, and if you still can’t figure it out, try creating a full repro that you can share. There’s really not enough code here to determine what is going wrong.