Reactjs 双标题堆栈导航

Reactjs 双标题堆栈导航,reactjs,react-native,react-navigation,Reactjs,React Native,React Navigation,我正在react本机应用程序中使用StackNavigator。 问题是,在我的应用程序中,它会创建两个标题 我想保留上一个从屏幕返回。是否可以不手动重新创建“后退”按钮 屏幕: class CommandsList extends React.Component { constructor(props){ super(props); } addCommand = () => { this.props.navigation.nav

我正在react本机应用程序中使用StackNavigator。 问题是,在我的应用程序中,它会创建两个标题

我想保留上一个从屏幕返回。是否可以不手动重新创建“后退”按钮

屏幕:

class CommandsList extends React.Component {
    constructor(props){
        super(props);
    }

    addCommand = () => {
        this.props.navigation.navigate("CreateCommand");
    }

    render() {
        return (
            <SafeAreaView style={{flex:1}}>
                <MyList itemsUrl="http://localhost:9000/commands"/>
                <Button title="Ajouter" onPress={this.addCommand}></Button>
            </SafeAreaView>
        );
    }
}

export default StackNavigator({
    CommandsList : {
        screen : CommandsList,
    },
});
class命令列表扩展了React.Component{
建造师(道具){
超级(道具);
}
addCommand=()=>{
this.props.navigation.navigate(“CreateCommand”);
}
render(){
返回(
);
}
}
导出默认堆栈导航器({
命令列表:{
屏幕:CommandsList,
},
});
编辑: App.js

const-navigationOptions=({navigation})=>({headerLeft:{navigation.goBack()}}/>})
const RootStack=StackNavigator(
{
命令列表:{
屏幕:CommandsList,
},
CreateCommand:{
屏幕:CreateCommand,
},
ListFournisseurs:{
屏幕:ListFournisseurs,
},
临时代办:{
屏幕:ListAffairs,
}
},
{
initialRouteName:'命令列表',
headerMode:“无”,
导航选项:{navigationOptions}
}
);

根据文档,如果要禁用
StackNavigator
标题
,可以在as
标题模式中应用配置:“无”
。它从子对象向后传播到父对象,如果父对象为无,则也不会呈现子对象

因此,对于单个标题,您应该这样做

export default StackNavigator({
    CommandsList : {
        screen : CommandsList,
    },
}, {
  headerMode: 'none'
});
对于父堆栈中的“上一步”按钮,可以按以下方式创建组件:

const navigationOptions = ({ navigation }) => ({
    headerLeft: <Icon name={'arrow-left'} //<== Vector Icon Here
     onPress={ () => { navigation.goBack() }} />

const RootStack = StackNavigator(
  RouteConfigs, 
  //... StackNavigatorConfigs,
  navigationOptions
)
const导航选项=({navigation})=>({
左校长:
const RootStack=StackNavigator(
路通图,
//…StackNavigator配置,
导航选项
)

你能为它添加导航路线吗?@PritishVaidya done:)我在每个屏幕上都有这个问题。我不知道如何添加导航选项而不出现导航选项错误?请检查并将类似我的导航选项添加到父堆栈中。正如你所说,我已经编辑了我的App.js(见我的初始帖子)而且仍然不起作用只要将它添加为
headerMode:'none',navigationOptions
,single object我实际上已经没有错误了,只需将
navigationOptions:navigationOptions
放进去,但它根本不起作用。
const navigationOptions = ({ navigation }) => ({
    headerLeft: <Icon name={'arrow-left'} //<== Vector Icon Here
     onPress={ () => { navigation.goBack() }} />

const RootStack = StackNavigator(
  RouteConfigs, 
  //... StackNavigatorConfigs,
  navigationOptions
)