# Issues with React Router and LoginwithRedirect

**URL:** <https://community.auth0.com/t/issues-with-react-router-and-loginwithredirect/150913>\
**Category:** Get Help\
**Tags:** signup-prompt-new-experience, login-experience\
**Created:** [November 3, 2024, 7:13pm UTC](https://community.auth0.com/t/issues-with-react-router-and-loginwithredirect/150913 "2024-11-03T19:13:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![solomonsokoya718](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/solomonsokoya718/32/61697_2.png) [@solomonsokoya718](https://community.auth0.com/u/solomonsokoya718)\
**Post date:** [November 3, 2024, 7:13pm UTC](https://community.auth0.com/t/issues-with-react-router-and-loginwithredirect/150913/1 "2024-11-03T19:13:02Z")

</div>

Hey all! I have two login buttons that should direct users to two different routes/components. However, when a user signs in and I provide a specific URL, the redirection always defaults to the root path (‘/’). Is there a way to resolve this issue, or could my current setup be incorrect?

````auto

ReactDOM.createRoot(document.getElementById("root")).render(
  <Auth0Provider
    domain={authConfig.domain}
    clientId={authConfig.clientId}
    authorizationParams={authConfig.authorizationParams}
  >
    <QueryClientProvider client={queryClient}>
      <BrowserRouter>
        <StyledEngineProvider injectFirst>
          <ThemeProvider theme={muiTheme}>
            <CssBaseline />
            <App />
          </ThemeProvider>
        </StyledEngineProvider>
        {import.meta.env.MODE === "development" && (
          <ReactQueryDevtools initialIsOpen={false} />
        )}
      </BrowserRouter>
    </QueryClientProvider>
  </Auth0Provider>,
);```

````

export const authConfig = {  
domain: …,  
clientId: …,  
authorizationParams: {  
redirect\_uri: window.location.origin,  
},  
};

```auto

```

const onButtonClick = async (e) =\> {  
e.preventDefault();  
await loginWithRedirect({  
redirect\_uri: `${window.location.origin}/beneficiary-application-page-1`,  
});  
};

```auto

```

```
  <Button variant="contained" onClick={() => loginWithRedirect()}>
    Login
  </Button>

```

```auto

```

const App = () =\> {  
return (  
  
{/\* Public Route \*/}  
\<Route path=“/” element={} /\>

```
  {/* Protected Routes */}
  <Route
    path="/dashboard"
    element={
      <ProtectedRoute>
        <Dashboard />
      </ProtectedRoute>
    }
  />
  <Route
    path="/feature-page-1"
    element={
      <ProtectedRoute>
        <FeaturePage1 />
      </ProtectedRoute>
    }
  />
  <Route
    path="/feature-page-2"
    element={
      <ProtectedRoute>
        <FeaturePage2 />
      </ProtectedRoute>
    }
  />
  <Route
    path="/profile-picture-page"
    element={
      <ProtectedRoute>
        <ProfilePicturePage />
      </ProtectedRoute>
    }
  />
  <Route
    path="/edit-page"
    element={
      <ProtectedRoute>
        <EditPage />
      </ProtectedRoute>
    }
  />
  <Route
    path="/application-step-1"
    element={
      <ProtectedRoute>
        <ApplicationStep1 />
      </ProtectedRoute>
    }
  />
  <Route
    path="/criteria-check"
    element={
      <ProtectedRoute>
        <CriteriaCheck />
      </ProtectedRoute>
    }
  />

  {/* Standalone route for dynamic content */}
  <Route path="/:dynamicId" element={<DynamicPage />} />
</Routes>

```

);  
};

export default App;

// ProtectedRoute.jsx  
import React from “react”;  
import { useAuth0 } from “@auth0/auth0-react”;  
import { Navigate } from “react-router-dom”;  
import { Box, CircularProgress } from “@mui/material”;

const ProtectedRoute = ({ children }) =\> {  
const { isAuthenticated, isLoading } = useAuth0();

if (isLoading) {  
return (  
\<Box  
sx={{  
display: “flex”,  
justifyContent: “center”,  
alignItems: “center”,  
height: “100vh”,  
}}  
\>  
  
  
);  
}

return isAuthenticated ? children : ;  
};

export default ProtectedRoute;

```auto

```

---

<div class="post-metadata">

**Author:** ![marybeth.hunter](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marybeth.hunter/32/61955_2.png) [@marybeth.hunter](https://community.auth0.com/u/marybeth.hunter)\
**Post date:** [November 8, 2024, 7:50pm UTC](https://community.auth0.com/t/issues-with-react-router-and-loginwithredirect/150913/3 "2024-11-08T19:50:15Z")

</div>

Hi @solomonsokoya718!

Can you confirm that both the `window.location.origin` and `${window.location.origin}/beneficiary-application-page-1` are listed in the Allowed Callback URLs of the tenant?

Is the `${window.location.origin}/beneficiary-application-page-1` a protected route? It’s difficult to tell from the code sample. Does that route call `loginWithRedirect()`?

I found this solution that may prove helpful to you if the answers to the last few questions are “yes”: [Angular app non stop refresh after login with code and state query string - #4 by frederik.prijck](https://community.auth0.com/t/angular-app-non-stop-refresh-after-login-with-code-and-state-query-string/106711/4)

Please let me know if I can assist further!

Thanks,

Mary Beth

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [November 22, 2024, 7:51pm UTC](https://community.auth0.com/t/issues-with-react-router-and-loginwithredirect/150913/4 "2024-11-22T19:51:07Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
