score:1

Accepted answer

Found the problem. In index.js I had React.StrictMode around my application. Removing it fixed the issue. I'm not sure exactly why that worked though.

score:0

index.js

import { BrowserRouter } from 'react-router-dom';

const defaultRender = () => {
    ReactDOM.render(
      <BrowserRouter>
        <App />
      </BrowserRouter>,
      document.getElementById('root')
    );
};
defaultRender();

App.js

import React from 'react';
import { Route, Switch } from 'react-router-dom';
import {Page1, Page2} from './pages';

const App = () => {
  return (
    <div className="App">
        <Switch>
          <Route exact path="/page1" component={Page1} />
          <Route exact path="/page2" component={Page2} />
        </Switch>
    </div>
  );
}

export default App;


Related Query

More Query from same tag