React Router v5恢复滚动位置

时间:2019-09-16 19:03:01

标签: reactjs react-router-v5

每次页面更改时,我都试图将滚动位置恢复到顶部。我不希望它滚动到顶部,我想通过单击链接使其位于顶部。

App.js

class App extends React.Component {
  render() {
    return (
      <Provider store={store}>
        <BrowserRouter style={{ height: "100%" }}>
          <Switch>
            <Route exact path="/login" component={AuthPage} />
            <Route exact path="/signup" component={Signup} />
            <Route exact path="/reset_user" component={ResetUser} />
          </Switch>
        </BrowserRouter>
      </Provider>
    );
  }
}

export default App;

index.js

ReactDOM.render(
  <App />,

  document.getElementById("root")
);

store.js

const initialState = {};

const middleware = [thunk];

const store = createStore(
    rootReducer,
    initialState,
    compose(
    applyMiddleware(...middleware),
    window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
))

export default store;

0 个答案:

没有答案