From 53f82b8e285985e7317f3e7fbcf5e2e2fea1f0e0 Mon Sep 17 00:00:00 2001 From: Martavis Parker <47053705+martavis@users.noreply.github.com> Date: Tue, 5 Oct 2021 09:04:24 -0700 Subject: [PATCH] Fixed scroll position across the app (#2375) * fixed scroll across the app * changes file --- changes/issue-2242-app-scroll | 1 + .../components/AuthenticatedRoutes/AuthenticatedRoutes.tsx | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changes/issue-2242-app-scroll diff --git a/changes/issue-2242-app-scroll b/changes/issue-2242-app-scroll new file mode 100644 index 0000000000..c7cc7971c0 --- /dev/null +++ b/changes/issue-2242-app-scroll @@ -0,0 +1 @@ +- Fixed scroll position when navigating to different pages \ No newline at end of file diff --git a/frontend/components/AuthenticatedRoutes/AuthenticatedRoutes.tsx b/frontend/components/AuthenticatedRoutes/AuthenticatedRoutes.tsx index 401050fc58..b7243b71a5 100644 --- a/frontend/components/AuthenticatedRoutes/AuthenticatedRoutes.tsx +++ b/frontend/components/AuthenticatedRoutes/AuthenticatedRoutes.tsx @@ -11,6 +11,7 @@ import { authToken } from "utilities/local"; interface IAppProps { children: JSX.Element; + location: any; // no type in react-router v3 } interface IRootState { @@ -22,7 +23,7 @@ interface IRootState { }; } -export const AuthenticatedRoutes = ({ children }: IAppProps) => { +export const AuthenticatedRoutes = ({ children, location }: IAppProps) => { const dispatch = useDispatch(); const { user } = useSelector((state: IRootState) => state.auth); const { locationBeforeTransitions } = useSelector( @@ -64,6 +65,10 @@ export const AuthenticatedRoutes = ({ children }: IAppProps) => { } }, [user]); + useDeepEffect(() => { + window.scrollTo(0, 0); + }, [location]); + if (!user) { return false; }