Reputation: 3953
I am trying to revamp my routing w expo-router, where the same route is navigated to multiple times, by using router.push('/item/[id]')
. However, when I navigate back()
it goes back to the top of the stack instead of from item/2
to item/1
Any ideas?
directory:
item
|__: _layout.tsx
|__: [id].tsx
item/_layout.tsx:
<Stack>
<Stack.Screen name="[id]" />
</Stack>
Inside the item
component, there is an onPress
event that gets captured like:
const handlePress = (label: string) => {
router.push({
pathname: `/pattern/[id]`, // I have also tried `/pattern/${label}`
params: { id: label, from: from },
});
};
The back button is:
<Pressable
onPress={router.back}
>
<Icon />
</Pressable>
Upvotes: 5
Views: 3022
Reputation: 31
Try adding an anonymous function inside onPress prop:
<Pressable
onPress={ ()=> router.back() }
>
<Icon />
</Pressable>
Upvotes: 2