expo / router

[ARCHIVE]: Expo Router has moved to expo/expo -- The File-based router for universal React Native apps

Home Page:https://docs.expo.dev/routing/introduction/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Navigation not working with nested navigator in v2

dasovm opened this issue · comments

Which package manager are you using? (Yarn is recommended)

yarn

Summary

I'm not getting navigation to work whenever there's a nested navigator in my segment-group. This worked with Router 1.x + Expo 48, but did break after upgrading to Router 2 + Expo 49. Whenever I try to navigate to a page (using the Link-component from Expo Router) I get the following error:

The action 'NAVIGATE' with payload {"name":"app"} was not handled by any navigator.

Do you have a screen named 'app'?

Minimal reproducible example

https://github.com/dasovm/expo-router-issue-768


Init a new repo using the SDK 49 tabs template:

npx create-expo-app@latest --template tabs@49

Use the following type of structure in the app-directory:

- _layout.tsx
- index.tsx
- (app)
  - _layout.tsx
  - app.tsx

In (app)/_layout.tsx just use a basic layout:

import { Stack } from "expo-router";
export default Stack;

In index.tsx use the following code:

export default function IndexPage() {
  return (
    <View>
      <Link href="/(app)/app">App</Link>
    </View>
  );
}

The navigation won't work and will throw the error mentioned above. If you then remove the Stack-layout from (app)/_layout.tsx (remove the file), it will then work again.

try with just

<Link href="/app">App</Link>

I believe with the way you have it its looking for (app)/(app)/app.tsx which doesn't exist.

Groups are not meant to be a part of the URL so it won't work if you specify a group id while navigating.

Isn't the whole concept of Shared Routes built upon using groups in the URL? Also it seems that some of the generated typed routes includes groups as well, so I guess that should be fine.

Anyway, I tried using only /app as href in the Link but unfortunately with the same result: got The action 'NAVIGATE' with payload {"name":"app"} was not handled by any navigator. as error in the console and no navigation happened.

I was wrong, docs do say you should be able to include the group in the href. Wonder if it's because they're named the same.. Do other group urls work? Maybe try something like (testA)/testB

Yes, if I remove the app/_layout.tsx-file in the example above, then navigating using <Link href="/(app)/app">App</Link> works for me.

I can confirm I am also experiencing this issue, in my case I thought using a (tabs) navigator was messing it up, but it turns out it was just the nested navigation as mentioned in the OP.

Can you please provide a full reproduction. I have followed the steps provided and was unable to replicate the issue. Your steps are missing information such as the contents of _layout.tsx. I tried to guess its contents but was still unable to reproduce the issue.

commented

Not the OP but I've recreated this on multiple devices. If you create an app with npx create-expo-app@latest --template tabs@sdk-49

  1. Move modal.tsx into a (modals) folder
  2. Create a _layout.tsx in that folder
import { Stack } from 'expo-router';
export default function ModalLayout () {
    return (
        <Stack>
            <Stack.Screen name="modal" />
        </Stack>
   )
}
  1. Change the RootLayoutNav name="modal" to name="(modals)"

The issue is navigating from one folder with a _layout.tsx to another with it also. Everything else works fine.

@marklawlor sure thing! I created a repo here: https://github.com/dasovm/expo-router-issue-768

The "To App"-link doesn't work for me in the repo above. I tried to look more into what could be the issue and found that it might be something with initialRouteName in app/_layout.tsx. If I remove that setting, the link works as expected.

Setting the following property seems to break navigation when you have a combo of stacks or tabs:

export const unstable_settings = {
  initialRouteName: '(auth)',
};

It will throw the following error:

 ERROR  The action 'NAVIGATE' with payload {"name":"home/index"} was not handled by any navigator.

Do you have a screen named 'home/index'?

Even though I do have a validhome/index screen.

This won't allow navigating to (app) later. Removing the above does allow it. navigation to work once again.

Setting the following property seems to break navigation when you have a combo of stacks or tabs:

export const unstable_settings = {
  initialRouteName: '(auth)',
};

It will throw the following error:

 ERROR  The action 'NAVIGATE' with payload {"name":"home/index"} was not handled by any navigator.

Do you have a screen named 'home/index'?

Even though I do have a validhome/index screen.

This won't allow navigating to (app) later. Removing the above does allow it. navigation to work once again.

Confirming the same problem. I have a Tabs nested within a Stack & cannot navigate to the Tabs.
But the current workaround is to remove the unstable_settings. Am able to navigate to the Tabs once the unstable_settings is removed or commented out.

Setting the following property seems to break navigation when you have a combo of stacks or tabs:

export const unstable_settings = {
  initialRouteName: '(auth)',
};

It will throw the following error:

 ERROR  The action 'NAVIGATE' with payload {"name":"home/index"} was not handled by any navigator.

Do you have a screen named 'home/index'?

Even though I do have a validhome/index screen.

This won't allow navigating to (app) later. Removing the above does allow it. navigation to work once again.

I'm also confirming this same issue. Removing the unstable_settings worked.

Setting the following property seems to break navigation when you have a combo of stacks or tabs:

export const unstable_settings = {
  initialRouteName: '(auth)',
};

It will throw the following error:

 ERROR  The action 'NAVIGATE' with payload {"name":"home/index"} was not handled by any navigator.

Do you have a screen named 'home/index'?

Even though I do have a validhome/index screen.

This won't allow navigating to (app) later. Removing the above does allow it. navigation to work once again.

Screenshot 2023-08-19 at 09 56 40

Exact same thing. I was wondering if this could break something in the future. I'll comment it out for now and see.

commented

Upgrading expo-router to latest version (2.0.4 as at this comment) solves this issue.

Fixed in 2.0.4. If your still have any issues can you please reply with a reproduction.

@marklawlor It doesn't seem to work.
Here is a simple reproduction repo https://github.com/mrkpatchaa/expo-router-modal-stack
Clicking on the right icon doesn't open the modal.

@mrkpatchaa That is a slightly different issue, the fix just got merged and should be published soon expo/expo#24166

Great. Thanks @marklawlor I'll test it once it's published.

@marklawlor I confirm version 2.0.5 works well.
Thanks 🎆

@marklawlor I am still able to reproduce this error on expo-router@2.0.5 using dasovm's minimal reproducible example.
Here are my steps

  1. git clone git@github.com:dasovm/expo-router-issue-768.git
  2. cd expo-router-issue-768
  3. yarn add expo-router@2.0.5
  4. running yarn install just to make sure everything is there, getting success Already up-to-date
  5. yarn start
  6. Scanning qr code and opening Expo Go on iPhone 14 PM
  7. Clicking the To App link inside of the example application
  8. Console and phone showing the bellow error:
 ERROR  The action 'NAVIGATE' with payload {"name":"app"} was not handled by any navigator.

Do you have a screen named 'app'?

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.

@svemat01 Did you intend to have an initialRouteName for your navigator? If so, then your navigator needs a Screen with the name index.

    <Stack>
-     <Stack.Screen name="(app)" options={{ headerShown: false }} />
+     <Stack.Screen name="index" />
    </Stack>

If you didn't intend this, then you should remove the unstable_settings

- export const unstable_settings = {
-  initialRouteName: "index",
- };

@marklawlor Thanks for the reply! But yes, I intend to have an initialRouteName however adding an index screen to the navigator as your reply suggests does not appear to fix the issue unfortunately.

Hello, I have the same issue where I have a combo of a Stack into Tabs and they don't render.

I'm on expo 49.0.8 and expo-router 2.0.5. This was working on a previous version of both expo and expo-router, it only started happening after I upgraded both to latest.

Additionally, and I'm not sure if this is related, but a slight difference for my setup is that if i remove unstable_settings, in the _layout where I have the Stack component, all pages defined there stop rendering. Right now I can only get them to render via setting them as modal in the Stack.Screen options with unstable_settings defined.

This is my file structure:

- app
  _layout.tsx
 index.tsx
 - (app)
    _layout.tsx -- Stack/Stack.Screen
    - (main)
       _layout.tsx -- Tab component

Similar issue, solved by upgrading to latest expo router (2.0.7).