expo / router

[ARCHIVE]: Expo Router has moved to expo/expo -- The File-based router for universal React Native apps
https://docs.expo.dev/routing/introduction/
1.36k stars 113 forks source link

Not able to pick initialRouteName in Expo Router when using stacked navigation #871

Closed NiksCode closed 1 year ago

NiksCode commented 1 year ago

Not sure what happened with all the description i wrote.

I cloned the sample Expo Navigation example project: https://github.com/expo/expo/tree/main/templates/expo-template-tabs

Added another folder/navigation route and in the parent _layout and attempted to set initialRouteName to be (tabs).

Screenshot 2023-08-30 at 11 19 52 PM

However, the app keeps rendering the screen from (bugtest) router group.

Link to github: https://github.com/NiksCode/expo-router-issue

marklawlor commented 1 year ago

Hi @NiksCode, hopefully this explanation helps you understand the setting

initialRouteName will not cause the (tabs) screen to render, it is expected that (bugtest) will render (as they both as /index and (bugtest) is higher in alphabetical order.

Without initialRouteName: Your navigation stack is: (bugtest). If the user presses back on their device it will close the app.

With initialRouteName: Your navigation stack is (tabs)->(bugtest). If the users presses back, they will be taken to the (tabs) screen.

initialRouteName adds an additional "route" to the navigation stack, even if the user hasn't been there. A popular usecase for this is social medial apps, where a user open a post by clicking on a link. When they press back, it takes them back to their feed (instead of closing the app).

These settings are still unstable and their names come from React Navigation (they are the navigator options). As they stabilise we're doing to revisits the documentation/naming convention.