gpt4 book ai didi

javascript - React Router 历史属性传入的内容是什么?

转载 作者:行者123 更新时间:2023-12-01 03:54:11 26 4
gpt4 key购买 nike

我正在使用 React Router(版本 4.0.0)和 Router组件有一个名为“history”的必需 Prop 。

我知道在以前版本的react-router中你可以导入browserHistoryhashHistory从包中取出并将其作为 history 传递支持<Router>但在 v4 中,这两个都不可用。

该项目的可用文档没有提及如何处理这个必需的历史 Prop herehere它引用 hashHistory软件包 v4 中不再提供导出功能。

有什么想法吗?

最佳答案

如果您想使用具有历史记录的组件,您应该导入来自“react-router”的 browserHistory 或 hashHistory

import { Router,browserHistory } from 'react-router';
<Router history={browserHistory} routes={...} />
or
import { Router,hashHistory } from 'react-router';
<Router history={hashHistory} routes={...} />

https://github.com/ReactTraining/react-router/tree/v3/docs

关于javascript - React Router <Router> 历史属性传入的内容是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42914466/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com