-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initialRouteName has no effect #723
Comments
Only when both |
I am running into this when deep linking from one tab with its own stack to another tab with its own stack. There is no back button for the deep linked page although, |
i know it's not a proper solution. for now am going with this. check out : #428 |
I'm able to use this to impact the router history with groups. My initial problem was I couldn't figure out how to have proper pop/push animations. I always wanted anything in (auth) group to pop and anything in (tabs) to push. Turned out I just had to export this in the root layout: export const unstable_settings = {
initialRouteName: '(auth)',
} |
Well, I'm running into the same issue. After running a few investigations, if you console.log each route component, you see that the components are really mounting, but the redirect is being redirected again to the index of (tabs), for some unknown reason. The render order is "initial route" > "login" > "(tabs)/index". I tested both reloading and from a fresh start. Clearing the cache with -c had no effect. However, if you don't navigate when the app loads, and you do a fast refresh from a change in the code, the route properly initiates in the correct route. However, any attempt to open the app defaults to tabOne in the template. Navigating from the Expo Go app, you go straight to "(tabs)/index". package.json
|
Same issue, I set |
The React Navigation -> Expo Router migration guide seems to imply that the With this in mind I think The docs could probably be a bit clearer that |
I have a case where my new app goes to (auth) >. index.tsx instead of (tabs) > index.tsx. initialRouteName doesnt work |
In that case, specify the initial route like this, |
But I wanted to go to (tabs)/index.tsx. I set the initialRouteName up to "(tabs)". I have up and used redirections |
Very confusing. Not only it doesn't work, but |
I encountered the same issue with 1. Loading Fonts and Authentication State in
|
Same here |
I think all solutions are confused. My solutions: Set the app/_layout.tsx import { useFonts } from "expo-font";
import { Stack } from "expo-router";
import * as SplashScreen from "expo-splash-screen";
import { useEffect } from "react";
import "react-native-reanimated";
SplashScreen.preventAutoHideAsync();
export default function RootLayout() {
const [loaded] = useFonts({
SpaceMono: require("../assets/fonts/SpaceMono-Regular.ttf"),
});
useEffect(() => {
if (loaded) {
SplashScreen.hideAsync();
}
}, [loaded]);
if (!loaded) {
return null;
}
return (
<Stack >
<Stack.Screen name="index" options={{ headerShown: false }} redirect />
<Stack.Screen name="login" options={{ headerShown: false }} />
<Stack.Screen name="about" options={{ headerShown: false }} />
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen name="+not-found" />
</Stack>
);
} Index page will redirects to first sibling page |
@osmanemin adding redirect did the trick 🎉🎉 |
I just created an
If |
@andres-dos-santos you are a true hero. It works perfectly. Thank you! |
What is the status of this will you guys make the |
Ran into the same issue, it would be good if the prop |
We ended up using react navigation directly which after a small amount of setup was much easier than trying to solve these issues and more intuitive regarding nested navigators |
I don't think |
Same here. I got two errors, the "Unmatched Route", which is resolved by changing the name of the _layout.tsx file to index. However, when doing this, the screen turns white as there are no redirects. How can you develop if you can't at least see what you're developing? Using react-navigation seems to be the best choice |
Flet the same 🥲 |
@osmanemin 's solution worked for me! |
Probably not the case for everyone here, but if you use shared routes or groups, remember that
Given a BottomTabs layout with groups within each tab, structured like this:
This would alphabetically match with Notice there's no index file within (tabs), as that would create an additional item in the BottomTab navbar. In this case, I only want the three specific items in my navbar: (index), (someRandomName) and (anotherRandomName). I tried added a What finally worked was renaming the groups:
I just added letters to the start of each group name so that it aplhabetically matches on my first group. I find it strange, but at least it works. |
I used to operate like this before.: app/(tabs)/index.js:
Operating like this now will be more elegant.:
|
@andres-dos-santos thank you! It did work |
This one works.
|
same issue, so annoying 😑 |
This was my approach and it works well for me, so I simply guide it to an index screen which holds the logic inside
and inside index use the passed initial param to guide it to the right screen to be displayed
Make sure every step of the way you parse the param into a boolean since it always stringifies it. |
I did something similar. In your case I would replace that if for isFirstOpen = appFirstOpened === "true"
|
Which package manager are you using? (Yarn is recommended)
npm
Summary
On a fresh Expo project with tabs and Typescript, the
unstable_settings.initialRouteName
has no effect.I also tested
<Stack initialRouteName=...>
and it also has no effect.Basically, any directory with parenthesis
(something)
alphabetically at the top becomes the default route, unless there is anindex
directory.This doesn't correlate with what's described in the documentation: https://expo.github.io/router/docs/features/routing/#layout-settings
Minimal reproducible example
Steps to reproduce:
Step 1, Environment
Step 2, Testing the effect
Duplicate
(tabs)
directory and rename the duplicate to(a)
Update some text in
(a)/index.ts
Add
<Stack.Screen name="(a)" options={{ headerShown: false }} />
into the<Stack>
Result:
(a)
will be the default route withoutunstable_settings.initialRouteName
is updated. You can set anything tounstable_settings.initialRouteName
, there is no effect.The text was updated successfully, but these errors were encountered: