繁体   English   中英

Router.js:135 Uncaught TypeError: Cannot read properties of undefined (reading 'style') in React Native

[英]Router.js:135 Uncaught TypeError: Cannot read properties of undefined (reading 'style') in React Native

我是 React Native 的新手。 我正在尝试使用“react-native-router-flux”中的路由器。 但我得到了这个错误:

Router.js:135 Uncaught TypeError: Cannot read properties of undefined (reading 'style')
    at Module../node_modules/react-native-router-flux/src/Router.js (Router.js:135)
    at __webpack_require__ (bootstrap:789)
    at fn (bootstrap:100)
    at Module../node_modules/react-native-router-flux/src/index.js (index.js:1)
    at __webpack_require__ (bootstrap:789)

我的 App.js:

import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { Router, Scene } from 'react-native-router-flux';


export default function App() {
  return (
    <View style={styles.container}>
      <Router>
      <Scene key="root">
        <Scene key="Home"
          component={Home}
          title="Home"
          initial
        />
        <Scene
          key="Forgotpassword"
          component={Forgotpassword}
          title="Forgotpassword"
        />
      </Scene>
    </Router>
    </View>
    
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
    padding: 8,
  }
});

我的 package.json:

"dependencies": {
   "@react-navigation/native": "^6.0.10",
   "@react-navigation/native-stack": "^6.6.2",
   "expo": "~45.0.0",
   "expo-status-bar": "~1.3.0",
   "react": "17.0.2",
   "react-dom": "17.0.2",
   "react-native": "0.68.2",
   "react-native-paper": "^4.12.1",
   "react-native-router-flux": "^4.3.1",
   "react-native-safe-area-context": "^4.2.4",
   "react-native-screens": "~3.11.1",
   "react-native-web": "0.17.7"
 },

编辑:早些时候我忘记在我的问题中添加样式。 现在我添加了我的问题。 给您带来的不便深表歉意。

您为您的“视图”提供了“styles.container”的样式,但我在您的代码中看不到您定义“样式”的任何地方。 您可以使用以下代码将自定义样式添加到您的视图中:

const styles = Stylesheet.create({
// Write the styles here similar to CSS but in camelcase
})

请记住从模块中的 react-native 导入样式表。 如果您已经在代码中定义了样式表。 请在您的问题中包括这一点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM