Skip to content

Commit

Permalink
Merge pull request #121 from ruiqi7/bugfix/general
Browse files Browse the repository at this point in the history
Define location state type
  • Loading branch information
nicolelim02 authored Nov 10, 2024
2 parents eabdce9 + db722a0 commit 0d744bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion frontend/src/components/NoDirectAccessRoutes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Navigate, Outlet, useLocation } from "react-router-dom";
import { LocationState } from "../../hooks/useAppNavigate";

const NoDirectAccessRoutes: React.FC = () => {
const location = useLocation();

if (location.state?.from !== "app-navigation") {
if ((location.state as LocationState)?.from !== "app-navigation") {
return <Navigate to="/home" replace />;
}

Expand Down
6 changes: 5 additions & 1 deletion frontend/src/hooks/useAppNavigate.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { useNavigate } from "react-router-dom";

export interface LocationState {
from: string;
}

export const useAppNavigate = () => {
const navigate = useNavigate();

const appNavigate = (path: string) => {
navigate(path, {
replace: location.pathname !== "/home",
state: { from: "app-navigation" },
state: { from: "app-navigation" } as LocationState,
});
};

Expand Down

0 comments on commit 0d744bf

Please sign in to comment.