reactjs - React Navigation 5 - 深度链接不接受给定路径并按预期解析为状态

标签 reactjs react-native react-navigation react-navigation-v5

我正在尝试为使用 React Navigation 5 的 React Native 应用程序使用深度链接,并且一直在关注:https://reactnavigation.org/docs/configuring-links

这是我的代码:

...

const App = observer(() => {
  const { NavTheme, themeLoaded } = useTheme();
  const linking = {
    prefixes: ['myurlhere://'],
    config: {
      screens: {
        Confirmed: {
          path: 'confirm'
        }
      }
    }
  };

  return (
    <NavigationContainer linking={linking} theme={NavTheme}>
      <LoginStack.Navigator>

        <LoginStack.Screen name="Login" component={Login} options={{ headerShown: false }}/>
        <LoginStack.Screen name="Confirmed" component={Confirmed} options={{ headerShown: false }}/>

      </LoginStack.Navigator>
    </NavigationContainer>
  );
});

当我转到 safari 并输入 myurlhere://confirm 时,它会打开应用程序,然后显示以下错误:

console.error: "The action 'NAVIGATE' with payload {"name":"confirm","params":{}} was not handled by any navigator.
Do you have a screen named 'confirm'?
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.

我希望它能导航到我的已确认路线。我做错了什么?

最佳答案

我假设你使用的是旧版本的 react-navigation

尝试像这样更改您的配置对象

const linking = {
  prefixes: ['myurlhere://'],
  config: {
    Confirmed: 'confirm'
  }
};

关于reactjs - React Navigation 5 - 深度链接不接受给定路径并按预期解析为状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62674058/

相关文章:

react-native - 路由 'ActivityFeed' 的组件必须是 React 组件

javascript - 是否有任何更新可以修复警告 'ViewPager Android has been extracted from react-native core' ?

javascript - 在ReactJS中修改状态对象直接重新渲染组件

reactjs - React-Native应用程序错误未知选项: .名称(?)

firebase - React Native 使用 .then() 中的 this.props 调用异步函数

javascript - 基于 redux 状态控制 react 组件的正确方法是什么

javascript - 如何反转 react native 矢量图标按钮颜色?

react-navigation - 在 IOS 中使用 react 导航的空白屏幕

reactjs - 检测SVG(React组件)路径元素的左侧或右侧部分被单击

javascript - 如何使用react-native解决 "Unable to resolve module..."错误?