Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-native: this.navigator.pop not working

I am new to react-native. I used the react-native-navbar package to go back to the previous route navbar component for react-native

when I click on the navbar button it shows me an error "undefined is not an object(evaluating 'this.navigator.pop')"

here is my snippet:

'use strict';
var React = require('react-native');
var {
    StyleSheet,
    Text,
    View,
} = React;
var NavigationBar = require('react-native-navbar');
var Demo = React.createClass({
    render: function()
    {
        var leftButtonConfig = {
          title: 'Back',
          handler: function onNext() {
            this.navigator.pop();
          }
        };

        var titleConfig = {
          title: 'Hello world page!',
        };
        return(
            <View style={{ flex: 1, }}>
      <NavigationBar
        title={titleConfig}
        leftButton={leftButtonConfig} />

            <View style={styles.container}>
        <Text style={styles.header}>
        Hello World
        </Text>
        </View>
        </View>
        );
    }
});
var styles = StyleSheet.create({
    container: {
        flex:1
    },
    header: {
        fontSize: 20,
        fontWeight: 'bold',
        textAlign: 'center'
    }
});

module.exports = Demo;
like image 373
Ankush Rishi Avatar asked May 18 '26 23:05

Ankush Rishi


1 Answers

this does not work onPress={() => navigation.pop()}

So, use this:

onPress={() => navigation.goBack()}

like image 84
Awara Amini Avatar answered May 20 '26 14:05

Awara Amini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!