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; }