-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed the rendering loop within the <Navigate .../> component
Signed-off-by: Daniel Einars <[email protected]>
- Loading branch information
1 parent
75e51c8
commit 9807cc7
Showing
9 changed files
with
87 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
import React from "react"; | ||
import { Navigate, Outlet } from "react-router-dom"; | ||
import { Navigate, Outlet, useLocation } from "react-router-dom"; | ||
|
||
import { selectIsAuthenticated } from "../store/auth/authSelectors"; | ||
import { useAppSelector } from "../store/store"; | ||
|
||
export function ProtectedRoute() { | ||
export function ProtectedRoutes() { | ||
const isAuth = useAppSelector(selectIsAuthenticated); | ||
const { pathname } = useLocation(); | ||
|
||
if (!isAuth) { | ||
return <Navigate to="/login" replace />; | ||
} | ||
|
||
return <Outlet />; | ||
return isAuth ? <Outlet /> : <Navigate to="login" state={{ from: pathname }} replace />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters