reactjs - 未能将 {history} 对象作为道具传递给路由器
问题描述
尝试将历史记录对象作为道具传递到我的路由器时出现以下错误。我刚刚将 history={history} 行添加到我的路由器中,出于某种原因它认为它不是传入的对象?
index.js:1446 警告:道具类型失败:提供给history
的道具类型无效,应为。function
Router
object
历史.js
import { createBrowserHistory } from 'history';
export default createBrowserHistory;
应用程序.js
import React from 'react';
import { Router, Route } from 'react-router-dom';
import PostCreate from './posts/PostCreate';
import PostList from './posts/PostList';
import Header from './Header';
import history from '../history';
const App = () => {
return (
<div className="ui container">
<Router history={history} >
<div>
<Header />
<Route path="/" exact component={PostList} />
<Route path="/posts/new" exact component={PostCreate} />
</div>
</Router>
</div>
);
};
export default App;
解决方案
我修好了它。在我的 history.js 中,我的 createBrowserHistory 末尾没有 ()。
历史.js
import { createBrowserHistory } from 'history';
export default createBrowserHistory();
推荐阅读
- azure-cognitive-search - Azure 认知搜索:搜索包含“-”的数据
- r - 跨行应用两个样本比例测试
- sharepoint - Graph API 403 Forbidden - 令牌中需要存在 scp 或角色声明
- apache-flink - Flink - 具有高并行度的网络缓冲区数量不足
- c# - 文本的重叠部分变得透明 GDI+
- rabbitmq - rabbitMq中的事件交换规则
- angular - Angular Reactive Forms:如何显示错误+红色边框?
- pandas - 如何删除列表中的那些列元素的行?
- python - 在 Python 中重新格式化 DataFrame
- javascript - Twitter引导模式在底部滚动条时侦听