# Issue with navigation after login

**URL:** <https://forum.ionicframework.com/t/issue-with-navigation-after-login/217455>\
**Category:** Ionic React\
**Created:** [November 17, 2021, 8:54pm UTC](https://forum.ionicframework.com/t/issue-with-navigation-after-login/217455 "2021-11-17T20:54:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonas.vankerckhove](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jonas.vankerckhove](https://forum.ionicframework.com/u/jonas.vankerckhove)\
**Post date:** [November 17, 2021, 8:54pm UTC](https://forum.ionicframework.com/t/issue-with-navigation-after-login/217455/1 "2021-11-17T20:54:06Z")

</div>

Hi all,  
I am having an issue with my login redirect. i have 2 Router and i want to switch when i log in or out between these 2. but my issue is you only see the switch is made after you refresh.  
If somebody could help me out with this

my routes

```auto
const Routing: React.FC = () => {
    return (
        <IonApp>
          <IonReactRouter>
              <IonRouterOutlet>
                <Route path="/login" component={Login} exact={true}>
                </Route>
                <Route path="/register" component={Register} exact={true}>
                </Route>
                <Route exact path="/">
                  <Redirect to="/login" />
                </Route>
              </IonRouterOutlet>
          </IonReactRouter>
        </IonApp>
    );
};

const RoutingAfterLog: React.FC = () => {
  return (
      <IonApp>
        <IonReactRouter>
          <IonTabs>
            <IonRouterOutlet>
              <Route path="/department" component={Department} exact={true}>
              </Route>
              <Route path="/department/id/products" component={Products} exact={true}>
              </Route>
              <Route path="/department/id/products/id" component={Product} exact={true}>
              </Route>
              <Route path="/home" component={Home} exact={true}>
              </Route>
              <Route path="/user" component={User} exact={true}>
              </Route>
              <Route exact path="/">
                <Redirect to="/home" />
              </Route>
            </IonRouterOutlet>
            <IonTabBar slot="bottom">
              <IonTabButton tab="department" href="/department">
                <IonIcon icon={cube} />
                <IonLabel>Stock</IonLabel>
              </IonTabButton>
              <IonTabButton tab="home" href="/home">
                <IonIcon icon={home} />
                <IonLabel>Home</IonLabel>
              </IonTabButton>
              <IonTabButton tab="user" href="/user">
                <IonIcon icon={person} />
                <IonLabel>User</IonLabel>
              </IonTabButton>
            </IonTabBar>
          </IonTabs>
        </IonReactRouter>
      </IonApp>
  );
};

```

here i check if i switch user state

```auto
useEffect(() => {
    getCurrentUser().then((user: any) => {
      if (user) {
        // logged in. Dispatch action from redux store in actions.ts file
        dispatch(setUserState(user.email));
        console.log(firebase.auth().currentUser?.email);
        //return <IonApp><RoutingAfterLog /></IonApp>;
        setUser(true)
        window.history.replaceState({}, "", "/home");
      } else {
        setUser(false)
        window.history.replaceState({}, "", "/");
      }
    });
  }, [dispatch]);

```

---

<div class="post-metadata">

**Author:** ![aaronksaunders](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/aaronksaunders/32/13729_2.png) [@aaronksaunders](https://forum.ionicframework.com/u/aaronksaunders)\
**Post date:** [November 23, 2021, 11:17pm UTC](https://forum.ionicframework.com/t/issue-with-navigation-after-login/217455/2 "2021-11-23T23:17:11Z")

</div>

> [@jonas.vankerckhove](#):
>
> ```auto
> window.history.replaceState({}, "", "/home");
> 
> ```

you should not use `window.history`

- [React Navigation: Router Link Redirect to Navigate to Another Page (ionicframework.com)](https://ionicframework.com/docs/react/navigation)
- [React Router: Declarative Routing for React.js](https://v5.reactrouter.com/web/api/Hooks/usehistory)

```auto
const history = useHistory();
history.push("/home");

```

---

<div class="post-metadata">

**Author:** ![jonas.vankerckhove](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jonas.vankerckhove](https://forum.ionicframework.com/u/jonas.vankerckhove)\
**Post date:** [November 24, 2021, 9:15am UTC](https://forum.ionicframework.com/t/issue-with-navigation-after-login/217455/3 "2021-11-24T09:15:02Z")

</div>

ok, thanks will look into it, this seems to work sometimes, but i still have to hit the refresh button now and then, is there a way to force a reload so it would always be working?
