# Page is refreshing every time a new route is clicked - React SPA

**URL:** <https://community.auth0.com/t/page-is-refreshing-every-time-a-new-route-is-clicked-react-spa/66597>\
**Category:** Get Help\
**Tags:** react, redirect, auth0\
**Created:** [July 22, 2021, 1:32pm UTC](https://community.auth0.com/t/page-is-refreshing-every-time-a-new-route-is-clicked-react-spa/66597 "2021-07-22T13:32:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Poolshark](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/poolshark/32/30418_2.png) [@Poolshark](https://community.auth0.com/u/Poolshark)\
**Post date:** [July 22, 2021, 1:32pm UTC](https://community.auth0.com/t/page-is-refreshing-every-time-a-new-route-is-clicked-react-spa/66597/1 "2021-07-22T13:32:35Z")

</div>

Hi,

I’m a bit confused if I have set up everything the right way. I basically have the following setup:

```auto
<BrowserRouter>
  <AuthProvider
    domain={ auth0Domain }
    clientId={ auth0ClientId }
    useRefreshToken={ true }
    redirectUri={ window.location.origin }
    cacheLocation="localstorage"
  >
    <App />
  </AuthProvider>
<BrowserRouter>

```

I have asked about the `cacheLocation` property in [another post](https://community.auth0.com/t/how-to-persist-login-with-auth0-react-after-page-refresh-without-localstorage/65777/4) but do not really understand the answer - in my opinion it does not matter if the information is stored in a cookie (which has to be accepted by the browser) or in the local storage. Anyway, this is working fine and my user keeps being logged in on a **page refresh.**

Unfortunately I have another problem now. I use `react-router` and thus I “switch back and forth” between different pages. My `<App />` component basically looks like so:

```auto
const App: React.FC = () => {

  const { isAuthenticated } = useAuth0();

  if ( isAuthenticated ) {
    return (
      <>        
        <Navbar />
        <Suspense fallback={ "Lazy loading pages ..." }>
          <Switch>
             <Route exact path="/" component={ Dashboard } />
             <Route path="/item1" component={ Item1 } />
             <Route path="/item2" component={ Item2 } />
         </Switch>
       </Suspense>
      </>
    );
  }

  return <Login />
};

```

My intention is that if the user is not logged in, he sees the **Login Page** and else the **Admin Interface** including the different routes. This also works fine so far but I realised that on every refresh, Auth0 checks the token and redirects. This is OK when refreshing the browser but not as nice when I click on my routes since the user sees the _Login Page_ for a short moment before seeing the appropriate content. I can over come this by setting the `isLoading` prop around the App component but also then I would see an entire different screen when clicking through my Nav Items…

Can someone please help? This is driving me crazy. I have also followed [this tutorial](https://auth0.com/blog/complete-guide-to-react-user-authentication/#Calling-an-API) but it seems that the same problem applies here.

---

<div class="post-metadata">

**Author:** ![Poolshark](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/poolshark/32/30418_2.png) [@Poolshark](https://community.auth0.com/u/Poolshark)\
**Post date:** [July 22, 2021, 2:00pm UTC](https://community.auth0.com/t/page-is-refreshing-every-time-a-new-route-is-clicked-react-spa/66597/2 "2021-07-22T14:00:56Z")

</div>

Just found the solution… I’m so sorry!!! I have used links with `href` instead od the Link component provided by **React Router.**

So make sure you have the

```auto
<Link to='/your-route'></Link>

```

from

```auto
import { Link } from 'react-router-dom'

```

and all is good.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 29, 2021, 10:18am UTC](https://community.auth0.com/t/page-is-refreshing-every-time-a-new-route-is-clicked-react-spa/66597/3 "2021-07-29T10:18:30Z")

</div>

Thanks for sharing it with the rest of community!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 29, 2021, 10:18am UTC](https://community.auth0.com/t/page-is-refreshing-every-time-a-new-route-is-clicked-react-spa/66597/4 "2021-07-29T10:18:34Z")

</div>


