Skip to content

Commit db722a0

Browse files
committed
Define location state type
1 parent eabdce9 commit db722a0

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

frontend/src/components/NoDirectAccessRoutes/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Navigate, Outlet, useLocation } from "react-router-dom";
2+
import { LocationState } from "../../hooks/useAppNavigate";
23

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

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

frontend/src/hooks/useAppNavigate.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { useNavigate } from "react-router-dom";
22

3+
export interface LocationState {
4+
from: string;
5+
}
6+
37
export const useAppNavigate = () => {
48
const navigate = useNavigate();
59

610
const appNavigate = (path: string) => {
711
navigate(path, {
812
replace: location.pathname !== "/home",
9-
state: { from: "app-navigation" },
13+
state: { from: "app-navigation" } as LocationState,
1014
});
1115
};
1216

0 commit comments

Comments
 (0)