为WEB设置反应导航失败

时间:2019-03-03 16:01:12

标签: react-native react-navigation react-router-dom react-native-web

我想将React Navigation 3.x与react-native-web结合使用。 通过执行“ getting started”步骤,

只需导入:

import { createStackNavigator, createAppContainer } from "react-navigation";

并更新babel配置,我最终收到此错误:

  

./ node_modules / @ react-navigation / native / node_modules / react-native-gesture-handler / Swipeable.js   找不到模块:无法解析“ D:\ react_native \ App \ app \ node_modules @ react-navigation \ native \ node_modules \ react”中的“ react-native / Libraries / Animated / src / AnimatedEvent ” -native-gesture-handler'

在研究中,我在github上发现了一些与该错误有关的主题: https://github.com/kmagiera/react-native-gesture-handler/pull/406

https://github.com/react-navigation/react-navigation/issues/5632

我已经使用了这个“修复”(来自上面的github拉)作为依赖:

"react-native-gesture-handler": "jaulz/react-native-gesture-handler#fix/web-compatibility"

但还是类似的错误:

  

./ node_modules / @ react-navigation / native / node_modules / react-native-gesture-handler / DrawerLayout.js   找不到模块:无法解决   ' react-native / Libraries / Animated / src / AnimatedEvent   'D:\ react_native \ App \ app \ node_modules @ react-navigation \ native \ node_modules \ react-native-gesture-handler'

如何通过反应导航在网络上实现有效的导航? 也许使用其他依赖版本? 还是我应该使用反应路由器?

1 个答案:

答案 0 :(得分:0)

这是一些设置说明 Web应用程序的反应导航。 https://reactnavigation.org/docs/en/web-support.html

简而言之:

yarn add @react-navigation/core yarn add @react-navigation/web

然后

import { createSwitchNavigator } from "@react-navigation/core"; import { createBrowserApp, Link } from "@react-navigation/web";

最终将createAppContainer替换为createBrowserApp