无法将历史记录 v5 与 RRD v6 一起使用,TS 错误类型“BrowserHistory”缺少类型“历史记录”中的以下属性:createURL、encodeLocation

问题描述 投票:0回答:1

我目前正在使用

React Router DOM v 6.8.1
history v 5.3.0
我只是按照这个例子

但是在尝试使用

history
HistoryRouter

时出现 TS 错误
<HistoryRouter history={history}>
   // code 
</HistoryRouter>

Type 'BrowserHistory' is missing the following properties from type 'History': createURL, encodeLocationts(2739)

这是codesandbox 上的示例

reactjs react-router-dom history.js
1个回答
0
投票

将 React Router DOM 版本更改为 6.3.0。它应该可以工作,或者使用定制的路由器功能。Refer to the Screenshot how to use a history in react-router dom

© www.soinside.com 2019 - 2024. All rights reserved.