diff --git a/pages/doc.js b/pages/doc.js index a5170e67706..6a5d1d55829 100644 --- a/pages/doc.js +++ b/pages/doc.js @@ -3,6 +3,7 @@ import React, { useCallback, useState, useEffect } from 'react' import PropTypes from 'prop-types' import Error from 'next/error' +import Router from 'next/router' // components import Page from '../src/Page' import { HeadInjector } from '../src/Documentation/HeadInjector' @@ -20,6 +21,7 @@ import sidebar, { getItemByPath } from '../src/Documentation/SidebarMenu/helper' import styled from 'styled-components' import { media } from '../src/styles' +const ROOT_ELEMENT = 'bodybag' const SIDEBAR_MENU = 'sidebar-menu' const parseHeadings = text => { @@ -69,6 +71,19 @@ export default function Documentation({ item, headings, markdown, errorCode }) { } }, [isSearchAvaible]) + useEffect(() => { + const handleRouteChange = () => { + const rootElement = document.getElementById(ROOT_ELEMENT) + if (rootElement) { + rootElement.scrollTop = 0 + } + } + + Router.events.on('routeChangeComplete', handleRouteChange) + + return () => Router.events.off('routeChangeComplete', handleRouteChange) + }, []) + const githubLink = `https://github.com/iterative/dvc.org/blob/master${source}` return (