本文主要是介绍RN在开发中遇到跳转页面时报错:Can't find variable: navigation,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
报错如下:
解决:在render函数内部添加:
const { navigation } = this.props;
相关代码如下:
Page1页面代码:
import React, { Component } from 'react';
import { Text, Button, View, StyleSheet } from 'react-native';
export default class Page1 extends Component {render() {const { navigation } = this.props;//不加这句会报错:Can't find variable: navigationreturn (<View style={styles.container}><Text>Welcome to Page1</Text><Button title = {'Go Back'}onPress = {()=>{navigation.goBack();}}/><Button title = {'跳转到Page4'}onPress = {()=>{navigation.navigate('Page4');}}/></View>);}
}
const styles = StyleSheet.create({container: {flex:1,}
})
这篇关于RN在开发中遇到跳转页面时报错:Can't find variable: navigation的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!