HuLu ViCa
HuLu ViCa

Reputation: 5450

React Router can't find History

I have this index.js in my React project:

import React from 'react';
import ReactDOM from 'react-dom';
import './css/main.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import {BrowserRouter as Router} from 'react-router-dom';

ReactDOM.render(
  <React.StrictMode>
    <Router>
      <App />
    </Router>
  </React.StrictMode>,
  document.getElementById('root')
);

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: 
serviceWorker.unregister();

And this is my app.js:

import React from 'react';
import {Routes, Route} from 'react-router';

import Catalogs from './components/pages/Catalogs';

function App() {
  return (
    <div>
      <Routes>
        <Route path="/" element={<Catalogs />} />
      </Routes>
    </div>
  );
}

export default App;

But I get this error when npm start: ./node_modules/react-router/index.js Module not found: Can't resolve 'history' in '/Users/hugovillalobos/Documents/Code/cinetogoproject/frontend/cinetogo/node_modules/react-router'

I don't know what I am missing.

Upvotes: 0

Views: 1926

Answers (2)

Mike Kokadii
Mike Kokadii

Reputation: 513

The problem may be in importing from react-router instead of react-router-dom in app.js

Upvotes: 0

HuLu ViCa
HuLu ViCa

Reputation: 5450

Documentation says nothing about it, but the problem, in my case, solves by installing history: npm install --save history

Upvotes: 3

Related Questions