diff --git a/src/App.tsx b/src/App.tsx index 63e4bf8..31a8d49 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -30,12 +30,14 @@ import { LabelPreviewPage } from './pages/dashboard/LabelPreviewPage'; import { StorePreviewPage } from './pages/StorePreviewPage'; import { LoadingProvider } from './context/LoadingContext'; import { Preloader } from './components/common/Preloader'; +import { ScrollToTop } from './components/common/ScrollToTop'; export const App: React.FC = () => { return ( + {/* Public Marketing & Informational Zone */} diff --git a/src/components/common/ScrollToTop.tsx b/src/components/common/ScrollToTop.tsx new file mode 100644 index 0000000..bb9f4de --- /dev/null +++ b/src/components/common/ScrollToTop.tsx @@ -0,0 +1,27 @@ +import React, { useEffect } from 'react'; +import { useLocation } from 'react-router-dom'; + +/** + * ScrollToTop component listens for route changes and automatically resets + * the viewport scroll position to the top of the page. + */ +export const ScrollToTop: React.FC = () => { + const { pathname, search } = useLocation(); + + useEffect(() => { + window.scrollTo({ + top: 0, + left: 0, + behavior: 'instant' as ScrollBehavior, + }); + + if (document.documentElement) { + document.documentElement.scrollTop = 0; + } + if (document.body) { + document.body.scrollTop = 0; + } + }, [pathname, search]); + + return null; +}; diff --git a/src/pages/LoginPage.tsx b/src/pages/LoginPage.tsx index 929ab11..86f0b2e 100644 --- a/src/pages/LoginPage.tsx +++ b/src/pages/LoginPage.tsx @@ -50,8 +50,17 @@ export const LoginPage: React.FC = ({ initialMode }) => { } else if (location.pathname === '/login') { setMode('login'); } + window.scrollTo({ top: 0, left: 0, behavior: 'instant' }); + if (document.documentElement) document.documentElement.scrollTop = 0; + if (document.body) document.body.scrollTop = 0; }, [location.pathname]); + useEffect(() => { + window.scrollTo({ top: 0, left: 0, behavior: 'instant' }); + if (document.documentElement) document.documentElement.scrollTop = 0; + if (document.body) document.body.scrollTop = 0; + }, [mode]); + // Login state const [mobileNumber, setMobileNumber] = useState(''); const [loginOtp, setLoginOtp] = useState('');