linkTo no longer working in React Navigation 7 - Stack Overflow

After updating to "@react-navigationnative": "^7.0.3", using linkTo from useLinkTo

After updating to "@react-navigation/native": "^7.0.3", using linkTo from useLinkTo() isn't working as it used to in ReactNative.

My linking config is somewhat complex:

const config = {
  screens: { // Root navigator: Menu Nav
    StackNav: {
      screens: {
        TabContainer: '/places',
        TabsNav: {
          screens: {
            Screen1: `/summary`,
            Screen2: '/stats',
          },
        },
        Screen3: '/account'
      }
    },
    Screen4: '/chat'
  }
}

...and using useLinkTo() to link to /stats isn't working anymore. It used to work in 6.x. I'm using it from within my own app to navigate when I might not have a It works fine so far for StackNav and ChatScreen, but not for anything in TabsNav.

What's happening:

  • RN seems to be able to find the route, if I comment out the /stats line in the config, it crashes when I try to nav saying: Error: Failed to parse the href to a navigation state.
  • RN just isn't navigating. It silently does nothing.
  • linkTo to /account works just fine

I know that with 7.x, navigating to nested navigators isn't supported and in the docs (.x/#changes-to-the-navigate-action) they explicitly mention that and how to use navigation.navigate(...) with some new props in order to do so.

But what about linkTo(...)? Was it also affected?

After updating to "@react-navigation/native": "^7.0.3", using linkTo from useLinkTo() isn't working as it used to in ReactNative.

My linking config is somewhat complex:

const config = {
  screens: { // Root navigator: Menu Nav
    StackNav: {
      screens: {
        TabContainer: '/places',
        TabsNav: {
          screens: {
            Screen1: `/summary`,
            Screen2: '/stats',
          },
        },
        Screen3: '/account'
      }
    },
    Screen4: '/chat'
  }
}

...and using useLinkTo() to link to /stats isn't working anymore. It used to work in 6.x. I'm using it from within my own app to navigate when I might not have a It works fine so far for StackNav and ChatScreen, but not for anything in TabsNav.

What's happening:

  • RN seems to be able to find the route, if I comment out the /stats line in the config, it crashes when I try to nav saying: Error: Failed to parse the href to a navigation state.
  • RN just isn't navigating. It silently does nothing.
  • linkTo to /account works just fine

I know that with 7.x, navigating to nested navigators isn't supported and in the docs (https://reactnavigation./docs/upgrading-from-6.x/#changes-to-the-navigate-action) they explicitly mention that and how to use navigation.navigate(...) with some new props in order to do so.

But what about linkTo(...)? Was it also affected?

Share Improve this question asked Nov 20, 2024 at 16:29 AndréAndré 4705 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Turns out I had to include the path to the navigator as well in the path.

Updated config to:

const config = {
  screens: { // Root navigator: Menu Nav
    StackNav: {
      screens: {
        TabsNav: {
          path: '/places',
          screens: {
            Screen1: `/summary`,
            Screen2: '/stats',
          },
        },
        Screen3: '/account'
      }
    },
    Screen4: '/chat'
  }
}

...and updated the linkTo from /stats to /places/stats.

Snack: https://snack.expo.dev/@acrabb713/143a82

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742344524a4426281.html

相关推荐

  • linkTo no longer working in React Navigation 7 - Stack Overflow

    After updating to "@react-navigationnative": "^7.0.3", using linkTo from useLinkTo

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信