我的React项目中有这个index.js
:
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();
这是我的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;
但是当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'
我不知道自己在想什么。
答案 0 :(得分:1)
文档对此一无所获,但就我而言,该问题通过安装历史记录来解决:npm install --save history
答案 1 :(得分:0)
问题可能出在从react-router
的{{1}}而不是react-router-dom
的{{1}}