Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue where scrolling was preserved when navigating #227

Merged
merged 6 commits into from
Jul 6, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions workspaces/ui/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useEffect } from 'react';
import './App.css';
import CssBaseline from '@material-ui/core/CssBaseline';
import { appTheme } from './theme';
import { BrowserRouter, Route } from 'react-router-dom';
import { BrowserRouter, Route, useLocation } from 'react-router-dom';
import { SnackbarProvider } from 'notistack';
import { ThemeProvider } from '@material-ui/core/styles';
import TopLevelRoutes from './entrypoints';
Expand All @@ -23,6 +23,7 @@ class App extends React.Component {
<ThemeProvider theme={appTheme}>
<SnackbarProvider maxSnack={1}>
<BrowserRouter>
<ScrollToTop/>
<>
<Route path="/" component={TopLevelRoutes} />
</>
Expand All @@ -32,7 +33,7 @@ class App extends React.Component {
</React.Fragment>
);
}
// Life cylce methods
// Life cycle methods
// ------------------
static getDerivedStateFromError(error) {
// Update state so the next render will show the fallback UI.
Expand Down Expand Up @@ -106,4 +107,16 @@ function AppError() {
);
}

// used to make sure we don't preserve scroll between pages

function ScrollToTop() {
const { pathname } = useLocation();

useEffect(() => {
window.scrollTo(0, 0);
}, [pathname]);

return null;
}

export default App;