const drawerNavigator = createDrawerNavigator({
HomeScreen: {
screen: customstack,
navigationOptions: {drawerLabel: () => null}
},
ContactAdmin : {screen : ContactAdmin},
ResetPasswordScreen: {
screen: ResetPassword,
navigationOptions: {drawerLabel: 'Reset Password',}
},
LogoutScreen: {
screen: Logout,
navigationOptions: {drawerLabel: 'Logout',}
},
NoNetwork : { screen : NoNetwork }
},
{
initialRouteName: 'HomeScreen',
gesturesEnabled: true,
style: {
leftDrawerWidth: 40,
},
drawerPosition :"left", contentComponent:SideMenu,
contentOptions: {
activeTintColor: '#e91e63',
},
navigationOptions: ({ navigation }) => ({
headerTitle: (
<View style={{flexDirection : 'row',flex :1,justifyContent:'center'}}>
<Image style={{width: 70, height: 40,backgroundColor:'white'}} source={require('./logo.png')} />
</View>
),
headerLeft:(<TouchableOpacity onPress={() =>navigation.toggleDrawer()}>
<Image style={{width: 25, height: 25,marginLeft:15}} source={require('./menu.png')} />
</TouchableOpacity>),
headerStyle: {
backgroundColor: '#008000'
}
})
},
);
const RootStack = createStackNavigator({
SplashScreen: { screen: SplashScreen },
Login: { screen: Login },
Signup: {screen: Signup},
Home: {screen: drawerNavigator,
},
}, {
initialRouteName: 'SplashScreen',
})
const AppNavigator = createAppContainer(RootStack)
export default AppNavigator;
上面的代码用作我的应用程序的导航器。现在在抽屉导航器中,当我进入重置密码并在成功操作后发送到登录屏幕时,我会像这样发送
。await AsyncStorage.removeItem('uname', (err) => {
this.props.navigation.navigate("Login")
});
直到现在一切都工作正常。在登录屏幕中输入新凭据后出现主要问题。它不会将我带到主屏幕,而仅在重置密码屏幕上。为什么会这样。成功登录后,我打电话
this.props.navigation.navigate("Home")
但它也会重置密码。如何清除抽屉导航,以便在使用新密码重新登录后再次使用它不会进入以前的屏幕,即重置密码
您将需要重置,这是他们文档中有关如何执行此操作的示例。我们希望这样做,因为我们希望防止返回到以前的状态,而是从全新的导航状态开始。
import { StackActions, NavigationActions } from 'react-navigation';
const resetAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'Profile' })],
});
this.props.navigation.dispatch(resetAction);
这里有一个指向上述示例的链接:https://reactnavigation.org/docs/en/stack-actions.html