我有React Native应用程序,当我需要返回时,我正在使用navigator.back()
。
但我注意到了这个问题
例如,如果我有三页A,B,C并且我从A开始,那么我转到B,转到C,然后返回到B,现在如果我打电话给navigator.back()
它会引导我到页面C,但我希望看到第A页。
有人知道如何解决这个问题吗?
以下是我的代码示例:
import React, { Component } from 'react'
import {
StyleSheet,
View,
StatusBar,
Navigator
} from 'react-native'
...
_renderScene (route, navigator) {
switch (route.name) {
case RouteName.Home:
return <Home navigator={navigator} />
case RouteName.Library:
return <Library navigator={navigator} />
case RouteName.BookDetails:
return <Details navigator={navigator} book={route.passProps.book} />
default:
console.error('Encountered unexpected route: ' + route.name)
}
return <Home />
}
...
export class Library extends React.Component {
constructor (props) {
super(props)
}
render(){
return (
<View style={styles.library}>
<Header title={LocalizationService.translate('MyLibrary')} navigator={this.props.navigator} />
<ScrollView>
<Accordion
ref='accordion'
sections={this.state.sections}
initiallyActiveSection={0}
renderHeader={this._renderHeader}
renderContent={this._renderContent.bind(this)}
/>
</ScrollView>
</View>
)
}
}
export class Header extends Component {
constructor (props) {
super(props)
this.state = {
title: ''
}
this._onClose = this._onClose.bind(this)
}
_onClose () {
let { onClose, navigator } = this.props
if (onClose) {
onClose()
} else {
navigator && navigator.pop()
}
}
}
Header.propTypes = {
title: React.PropTypes.string,
navigator: React.PropTypes.object,
onClose: React.PropTypes.func
}
答案 0 :(得分:0)
您正在寻找的方法似乎是navigator.pop()
https://facebook.github.io/react-native/docs/navigator.html#pop
调用libboost_python3.so
将卸载堆栈顶部的组件并转到上一个组件。