Prashant Jangid
Prashant Jangid

Reputation: 135

react navigation reset and redirect to home screen

I want to reset navigation when user logged in after then we will redirect to home page i have try this

        

    const Root = StackNavigator({
                 Unauthorized: { screen: UnAuthorized },
                 Authorized: { screen: Authorized },
               }, {
                    headerMode: 'screen',
                    navigationOptions: {
                    header: null
                 }
         });

       const Authorized = DrawerNavigator({
                        Home: { screen: Home }        
              });

       const UnAuthorized = StackNavigator({
                 Splash: { screen: Splash },
                 Login: { screen: Login },
              });


 await axios.post(url+'rest_users/login',user)
    .then(function (response) {
      dispatch({
        type: LOGGED_IN,
        payload: response.data
      });
      const resetNavigator = NavigationActions.reset({
        index: 0,
        key: null,
        actions: [
          NavigationActions.navigate({
            routeName: 'Authorized',
            action: [
              NavigationActions.navigate({routeName: 'Home'})]
          })
        ],
      });
      dispatch(resetNavigator);

Navigation showing reset in logs but i have not seen any screen moving changes. Please help me where i am going wrong

Upvotes: 0

Views: 704

Answers (1)

Eduard
Eduard

Reputation: 9165

As it seems, you are using dispatch method of Redux, not React-Navigation in order to dispatch your resetAction.

What you should do is pass navigation prop from your component to the place where you need to dispatch the resetAction and then call navigation.dispatch(resetAction)

Upvotes: 2

Related Questions