I am encountering an issue related to navigating in Expo Router.
image of my project's navigator hierarchy
As shown in the screenshot above, I have configured my router in the following way. I defined the Stack Navigator in app/_layout.tsx
, the Tabs Navigator in app/(tabs)/_layout.tsx
, and a separate Stack Navigator in each tab (home/profile) to display multiple screens within the same tab.
Here's where the problem occurred:
(router
is returned object from useRouter hook)
- Executed
router.push
from the/
router to the/home
router. - Executed
router.push
from the/home
router to the/welcome
router. - In order to return to the home tab, executed
router.push
to the/home
router.
Upon executing the third step, instead of going to /home
, it navigated back to /
.
Through various tests, I found out that the problem is caused by the Stack Navigator nested inside the Tabs Navigator. When I removed the _layout.tsx
files from (tabs)/home
and (tabs)/profile
, the problem disappeared.
However, I need to define the Stack Navigator in the (tabs)/home,profile/_layout.tsx
file as I need to display multiple screens in each tab.
What can I do to make this work as intended?
I'm dying to solve this problem. I would really appreciate it if you could help me.