Repository: expo/router

Issue #793: Bug: Cannot redirect/push to sibling route inside (group)/_layout
Created: 2023-07-18T01:53:58Z
Which package manager are you using? (Yarn is recommended)
None
Summary
Redirecting within a group's layout will cause errors.
    console.error
      The action 'REPLACE' with payload {"name":"should-work"} was not handled by any navigator.
      
      Do you have a screen named 'should-work'?
      
      If you're trying to navigate to a screen in a nested navigator, see https://reactnavigation.org/docs/nesting-navigators#navigating-to-a-screen-in-a-
nested-navigator.
      
      This is a development-only warning and won't be shown in production.

Most likely caused by isMovingToSiblingRoute incorrectly detecting the group of the last state
Minimal reproducible example
it("can redirect within a group layout", () => {
  renderRouter({
    "(group)/_layout": function Component() {
      const pathname = usePathname();

      if (pathname === "/") {
        return <Redirect href="/should-work" />;
      }

      return <Stack />;
    },
    "(group)/index": () => <Text />,
    "(group)/should-work": () => <Text />,
  });

  expect(screen).toHavePathname("/should-work");
});

Duplicate issue #947: Navigate in expo-router v4.0.17 leave screen in blank
Created: 2025-03-04T19:30:12Z
Hi!
When I created app with expo:
npx create-expo-app@latest ./
npm run reset-project
When navigate 4 or 5 times with "router.navigate('/path')" lost header and screen goes blank.
Dependencies
"expo": "~52.0.37",
"expo-router": "~4.0.17",
"react": "18.3.1",
"react-native": "0.76.7",
Step to reproduce issue
npx expo start
Navigate through the routes with the first button 4 or 5 times
* Happens on Android (tested on a physical device v14), does not happen on the web
Code
https://github.com/raszagar/rn-bug-expo-router
/app/_layout.tsx
import { Stack } from "expo-router";

export default function RootLayout() {
  return (
    <Stack screenOptions={{
      headerShown: true,
    }} />
  );
}
/app/root.tsx
import { router } from "expo-router";
import { Button, Text, View } from "react-native";


export default function RootScreen() {

    return (
        <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
            <Text>Root Screen</Text>
            <Button title="Go to Home" onPress={() => { router.navigate('/home')}} />
            <Text></Text>
            <Button title="Go to Profile" onPress={() => { router.navigate('/profile')}} />
        </View>
    );
}
/app/index.tsx
import { Redirect, router } from "expo-router";
import { Button, Text, View } from "react-native";

export default function Index() {
  return <Redirect href="/root" />;
}
/app/(tabs)/_layout.tsx
import { Stack } from "expo-router";

export default function TabsLayout() {
  return (
    <Stack screenOptions={{
      headerShown: true,
    }} />
  );
}
/app/(tabs)/home.tsx
import { router } from "expo-router";
import { Button, Text, View } from "react-native";


export default function HomeScreen() {

    return(
        <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
            <Text>Home Screen</Text>
            <Button title="Go to Profile" onPress={() => { router.navigate('/profile')}} />
            <Text> </Text>
            <Button title="Go to Root" onPress={() => { router.navigate('/root')}} />
        </View>
    );
}
/app/(tabs)/profile.tsx
import { router } from "expo-router";
import { Button, Text, View } from "react-native";


export default function ProfileScreen() {

    return(
        <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
            <Text>Profile Screen</Text>
            <Button title="Go to Home" onPress={() => { router.navigate('/home')}} />
            <Text> </Text>
            <Button title="Go to Root" onPress={() => { router.navigate('/root')}} />
        </View>
    );
}

Version 3.5.23 works fine
Downgrading the version of expo-router to v3.5.23 works fine.

Closing comment (2025-03-07T10:59:39Z): @raszagar started experiencing the same today when I actually run it on a device, works fine on the simulator. After some digging seems related to #793 I'm working around it by using useEffect
Instead of
if (!isSignedIn) {
  return <Redirect href="/signup" />;
}
I'm doing
useEffect(() => {
  if (!isSignedIn) {
    router.replace('/signup');
  }
}, [isSignedIn]);
Seems like historically it has had problems, but I hope it get's sorted soon, I really like the simplicity of <Redirect />