我要在“男士”标签中从产品屏幕转到购物车屏幕。
我的零食代码:https://snack.expo.io/@alirezadarvishi/full-screen-modal-v3
目标:我想进入购物车屏幕,点击男士标签中的cart screen
按钮。
主要路线:
const AppNavigatorLoggedin = createStackNavigator({
Home: {
screen: HomeScreen,
navigationOptions: () => ({
header: null,
}),
},
Products: {
screen: ProductsShow,
navigationOptions: () => ({
header: null,
}),
},
Cart: {
screen: CartScreen,
navigationOptions: () => ({
header: null,
}),
},
}, {
initialRouteName: 'Home',
mode: 'modal',
headerMode: 'none',
});
标签路线:
const MenStack = createStackNavigator({
menStackNav: { screen: MenTabScreen, navigationOptions:{tabBarVisible: false},
},
Products: {
screen: ProductsShow,
navigationOptions:{tabBarVisible: false},
}
},{
initialRouteName: 'menStackNav',
headerMode: 'none',
navigationOptions: {
headerVisible: false,
}
});
MenStack.navigationOptions = ({navigation}) => {
let tabBarVisible = true;
if(navigation.state.index > 0){
tabBarVisible = false;
}
return {
tabBarVisible,
}
}
const WomenStack = createStackNavigator({
WomenStacknav: { screen: WomenTabScreen, navigationOptions:{tabBarVisible: false},
},
Products: {
screen: ProductsShow,
navigationOptions:{tabBarVisible: false},
}
},{
initialRouteName: 'WomenStacknav',
headerMode: 'none',
navigationOptions: {
headerVisible: false,
}
});
WomenStack.navigationOptions = ({navigation}) => {
let tabBarVisible = true;
if(navigation.state.index > 0){
tabBarVisible = false;
}
return {
tabBarVisible,
}
}
const HomeScreenTabs = createMaterialTopTabNavigator({
Women: {
screen:WomenStack,
},
Men: {
screen:MenStack,
},
},{
initialRouteName: 'Men',
mode: 'modal',
headerMode: 'none',
});
男士标签页:
<View style={{marginTop:100}}>
<Button onPress={()=>{this.props.navigation.navigate('Products' , )}} title="product screen"/>
</View>
现在,当我单击按钮不起作用时,我看到错误。
错误:没有为购物车定义任何路线。必须是以下之一: 'menStackNav','产品'
为什么不工作?我该如何解决?
答案 0 :(得分:0)
goBack()
,如果您想回到老家。
goBack
-关闭活动屏幕并移回堆栈中
当可以从活动屏幕返回时,堆栈导航器提供的标题将自动包含一个后退按钮(如果导航堆栈中只有一个屏幕,则无法返回任何内容,依此类推没有back button
)。
<Button title="Cart screen" onPress={() => { this.props.navigation.goBack(); }} />