scroll to top on react react-router-dom page change

I’m using react-router-dom for implementing routing of my reactjs App!
but I have an issue with this , in which I can’t find any working solution for scroll to top on page changing. can any body help me???

here is my routing piece of code:

    <BrowserRouter  basename={basename}> 
          <Switch>
                    <MobilePage hasNav navType="primary" exact path={`/restaurant`} component={VendorList} />
                    <MobilePage hasNav navType="primary" path={`/restaurant/:vendorCode`} component={VendorDetails} /> 
          </Switch>
    </BrowserRouter>

16 thoughts on “scroll to top on react react-router-dom page change”

Leave a Comment