add scroll to top on route change

This commit is contained in:
Barry Gitarts 2019-08-30 08:25:02 -04:00 committed by Barry G
parent f3403b3ec1
commit 4cd670d79e

View File

@ -156,6 +156,20 @@ function PersistentDrawerLeft({ loading, account, children, enableEthereum, loca
const [logs, setLogs] = useState([]) const [logs, setLogs] = useState([])
const position = useWindowScrollPosition() const position = useWindowScrollPosition()
useEffect(() => {
try {
// trying to use new API - https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo
window.scroll({
top: 0,
left: 0,
behavior: 'smooth',
});
} catch (error) {
// just a fallback for older browsers
window.scrollTo(0, 0);
}
}, [pathname, search])
useEffect(() => { useEffect(() => {
const queryParams = queryString.parse(search) const queryParams = queryString.parse(search)
if (queryParams.logs) enableLogs() if (queryParams.logs) enableLogs()