简体   繁体   English

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

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

I created common header for all pages, so create header component then i include that header in signup.js component goback navigation function working in signup.js page but not working header component getting undefined object navigate.goback error 我为所有页面创建了通用标头,因此创建了标头组件,然后将该标头包含在signup.js页面中可使用的signup.js组件goback导航功能中,但未使用标头组件获取未定义的对象navigation.goback错误

Anyone give a solution for that like that i include component 任何人都为此提供解决方案,包括组件

sample code: 样例代码:

 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 } }); 

you need to use this inside the header component : 您需要在标题组件中使用它:

import { withRouter } from 'react-router'

and then instead of export default HeaderClassName 然后代替export default HeaderClassName

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

and you can go back by this.props.history.goBack() 您可以返回this.props.history.goBack()

You need to use this too: 您也需要使用此:

<BrowserRouter>
<App />

and then add the pages like that 然后添加类似的页面

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

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

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