未捕获的TypeError:无法读取未定义的属性'路径名'-在反应16.12中

时间:2020-06-09 10:26:36

标签: reactjs routes pathname

我在React项目中遇到此错误。我正在将React从15.8升级到16.12。

我还可以在bundle.js中看到以下行的相关错误消息

this.props.history.location.pathname

我正在路由器中提供历史记录,例如:

const components = <Router history={history}>AppRoutes()</Router>

我使用的包裹:

 "react": "^16.12",
 "history": "^2.0.0",
 "react-router": "^4.2.0",
 "react-router-dom": "^5.2.0",

我的软件包配置是否错误?如果是,应该是什么。 这是我的相关代码

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
import { createHistory } from "history";
import { Provider } from "react-redux";
import { Router } from "react-router";
import { syncHistoryWithStore } from "react-router-redux";
import useScroll from "scroll-behavior/lib/useStandardScroll";


const _browserHistory = useScroll(() => createHistory)();

export const store = createStore(reducer, _browserHistory, client, window.__data);
const history = syncHistoryWithStore(createHistory(), store);

const component = <Router history={history}>{AppRoutes()}</Router>;

0 个答案:

没有答案