[英]React-native: this.navigator.pop not working
我是本机反应的新手。 我使用 react-native-navbar 包返回到之前的路由 导航栏组件进行 react-native
当我点击导航栏按钮时,它显示一个错误“ undefined is not an object(evaluating 'this.navigator.pop')
”
这是我的片段:
'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;
您只需将其称为道具即可。
正如他们在示例中使用的那样
this.props.navigator.pop()
在路由时,导航使用作为道具传递给组件,以便更轻松地何时向屏幕堆栈弹出。 顺便说一句, wix-navigation可以替代这个,并且有一个很好的文档。
根据 react native navigation 7.0.0 文档,您需要import { Navigation } from 'react-native-navigation';
然后在后退按钮点击你需要写Navigation.pop(this.props.componentId, { component: { name: 'ComponentName', } })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.