尝试使用 React Router v6 时出错:尝试导入错误:“操作"未从“历史记录"导出 [英] Getting error when try to use React Router v6: Attempted import error: 'Action' is not exported from 'history'
问题描述
我使用
创建了一个新的反应应用程序npx create-react-app app-name
然后我将目录更改为该应用程序文件夹,然后运行以下命令.
npm install react-router@next react-router-dom@next
然后我运行了我的应用程序,它运行良好.然后我改了默认代码,使用了Routes、Route等,这里是APP代码
从'react'导入React;从react-router-dom"导入{BrowserRouter 作为路由器、路由、路由};功能应用(){返回 (<路由器><路线><路由路径="/";element={ }/></路线></路由器>);}函数主页(){返回 <h1>首页</h1>}导出默认应用程序;
我收到错误:
尝试导入错误:操作"未从历史记录"导出.
错误路径为:
./node_modules/react-router/index.js
知道它有什么问题吗?
我的代码没有任何问题.也许问题出在最新版本的 React-Router 上.所以,我只是改变了 React-Router 的版本.
来自
react-router":^6.0.0-beta.0";react-router-dom":^6.0.0-beta.0"
至
react-router":6.0.0-alpha.2",react-router-dom":6.0.0-alpha.2"
它工作得很好,没有任何问题.我在我的问题中提到的相同代码无需任何更改即可正常工作.:)
I have created a new react application using
npx create-react-app app-name
Then I changed my directory to that app folder and then ran the following command.
npm install react-router@next react-router-dom@next
Then I ran my application and it worked fine. Then I changed the default code and used Routes, Route, etc. Here is APP code
import React from 'react';
import {BrowserRouter as Router, Routes, Route} from "react-router-dom"
function App() {
return (
<Router>
<Routes>
<Route path="/" element={<Home />} />
</Routes>
</Router>
);
}
function Home()
{
return <div>
<h1>Home</h1>
</div>
}
export default App;
I get the error:
Attempted import error: 'Action' is not exported from 'history'.
Path of the error is:
./node_modules/react-router/index.js
Any Idea what is wrong with it?
There is nothing wrong with my code. Maybe the issue is with the latest version of React-Router. So, I just changed the version of React-Router.
FROM
"react-router": "^6.0.0-beta.0"
"react-router-dom": "^6.0.0-beta.0"
TO
"react-router": "6.0.0-alpha.2",
"react-router-dom": "6.0.0-alpha.2"
It is working absolutely fine with no problems. The same code that I have mentioned in my question is working fine without any change. :)
这篇关于尝试使用 React Router v6 时出错:尝试导入错误:“操作"未从“历史记录"导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!