以多种不同的形式询问了此问题,我整周都进行了搜索,但无法确定如何在下面的设置中从Connect
回到Devices
。
const HomeStack = createStackNavigator({
Devices: DevicesScreen,
Details: DetailsScreen, // go here
})
const NewDeviceStack = createStackNavigator({
Start: StartScreen,
Connect: ConnectScreen, // start here
})
const BottomTabs = createBottomTabNavigator(
{
Home: { screen: HomeStack },
Settings: { screen: NewDeviceStack },
}
export default createAppContainer(BottomTabs);
在Connect
屏幕上,此代码尝试重置当前堆栈并返回到Devices
const resetAction = StackActions.reset({
index: 0,
key: null,
actions: [
NavigationActions.navigate({routeName: 'Devices'})
],
})
this.props.navigation.dispatch(resetAction)
此操作失败,并显示以下信息:
Error: There is no route defined for key Devices.
Must be one of: 'Start','Connect'
答案 0 :(得分:1)
使用navigation
道具,单击按钮即可导航到设备屏幕
this.props.navigation.navigate('Devices')
或仅创建一个处理导航的功能
goToScreen = (routeName, params = {}) => {
const navigateAction = NavigationActions.navigate({
routeName: routeName,
params: params, // parameter
action: NavigationActions.navigate({ routeName: routeName }), // screen you want to navigate to
});
this.props.navigation.dispatch(navigateAction);
};