Skip to content

Commit

Permalink
Define location state type
Browse files Browse the repository at this point in the history
  • Loading branch information
ruiqi7 committed Nov 10, 2024
1 parent eabdce9 commit db722a0
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 db722a0

Please sign in to comment.