[英]TypeError: props.history.listen is not a function. I am using ReactJS
Why is this showing?为什么会出现这个? I am using ReacJS and I can not see what is wrong.
我正在使用 ReacJS,但我看不出有什么问题。
My history.js:我的history.js:
import { createBrowserHistory } from 'history'
export default createBrowserHistory
My App.js:我的 App.js:
import React from 'react'
import { Router } from 'react-router-dom'
import Routes from './routes'
import history from './history'
import './styles/global.scss'
function App() {
return (
<div className="App">
<Router history={history}>
<Routes/>
</Router>
</div>
);
}
export default App;
You need to invoke createBrowserHistory
and then export it.您需要调用
createBrowserHistory
然后将其导出。 Try changing the line to:尝试将行更改为:
export default createBrowserHistory();
This is the proper way to import Router component,the root router component which takes history as a prop.这是导入Router组件的正确方法,Router组件是以历史为道具的根路由器组件。
import { BrowserRouter as Router } from "react-router-dom";
and as Sajib Khan
said, you should also call the createBrowserHistory
then use it as history prop.正如
Sajib Khan
所说,您还应该调用createBrowserHistory
然后将其用作历史道具。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.