繁体   English   中英

反应本机堆栈导航goBack()不起作用

[英]React native stack navigation goBack() not working

我为所有页面创建了通用标头,因此创建了标头组件,然后将该标头包含在signup.js页面中可使用的signup.js组件goback导航功能中,但未使用标头组件获取未定义的对象navigation.goback错误

任何人都为此提供解决方案,包括组件

样例代码:

 import React from 'react'; import { StyleSheet, Text, View, Image, ScrollView, TextInput,KeyboardAvoidingView, StatusBar } from 'react-native'; import {Icon,Body,Button,Title,Left,Right} from 'native-base'; import Expo from "expo"; import { Constants } from 'expo'; import Headerbar from "./../Header/header"; import Statusbar from "./../statusbar"; const googleIcon=require('../../../img/google_icon.png'); const fbIcon=require('../../../img/fb_icon.png'); export default class Socialsignup extends React.Component { constructor(props) { super(props); this.state = { }; } render() { return ( <ScrollView style={styles.socialContainer} scrollEnabled={true}> <Statusbar/> <Headerbar title="Social Login" /> <View style={styles.socialText}> <Text style={styles.accountText}>Choose an account</Text> </View> <View style={styles.socialIconsBase}> <View style={styles.socialIconsGoogle}> <Image source={googleIcon} style={styles.googleIcon}/> <Text style={styles.iconText}> Google </Text> </View> <View style={styles.socialIconsGoogle}> <Image source={fbIcon} style={styles.fbIcon}/> <Text style={styles.iconText}> Facebook </Text> </View> </View> </ScrollView> ); } } const styles = StyleSheet.create({ socialContainer: { backgroundColor: '#fff', }, accountText: { marginTop:25, fontSize:20, padding:20 }, socialIconsBase: { flexDirection:'row', flex:1, marginTop:40, borderBottomWidth:1, borderBottomColor:'#a8c0ce' }, socialIconsGoogle: { flex:1, alignItems:'center', paddingTop:25, paddingBottom:25, borderRightWidth:1, borderRightColor:'#a8c0ce', marginBottom:8, }, fbIcon:{ height:50, width:50, }, googleIcon:{ height:50, width:50, }, iconText:{ fontSize:15, marginTop:15 } }); 

您需要在标题组件中使用它:

import { withRouter } from 'react-router'

然后代替export default HeaderClassName

export default withRouter(HeaderClassName)使用export default withRouter(HeaderClassName)

您可以返回this.props.history.goBack()

您也需要使用此:

<BrowserRouter>
<App />

然后添加类似的页面

<Route path='/page' component={Page} />

暂无
暂无

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

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