this.props.history已被弃用(react router)
this.props.history is deprecated (react-router)
我试图用程序导航到另一个页面,就像this.props.history.push('/new-path');
一样,它起作用了,但我在控制台中收到了一条弃用警告,说:
Warning: [react-router] props.history and context.history are deprecated. Please use context.router.
点击此处了解更多信息https://github.com/reactjs/react-router/blob/master/upgrade-guides/v2.0.0.md#changes-到这个上下文
之后,我尝试像this.context.router.push('/new-path')
一样使用这种新方法,但这似乎不是正确的方法。
也许您忘记将路由器定义为contextType?假设你有一个像这样的组件
class YourComponent extends React.Component {
render() {
return <div></div>;
}
}
您必须在组件下面定义如下contextTypes:
YourComponent.contextTypes = {
router: React.PropTypes.object.isRequired
};
相关文章:
- react router router.HistoryLocation以<noscript>但没有完美的工作
- React Router一直给我一个警告:你不能更改<路由器路由>
- 使用react router/react router redux将特定的redux操作绑定到一个路由
- 组件未使用ReactJS和React Router进行渲染
- React Router,在params之后嵌套路由
- 如何在 React-router 中手动调用 Link
- 我的React应用程序的根文件夹与React Router冲突
- React-router 在添加历史记录后不会渲染组件
- 直接使用 React Router + React + Flux 路由到 URL
- 对不同的路由使用相同的组件与 React Router
- 如何使用React Router在Route Handler上获取参数
- React Router浏览器历史记录适用于本地,而不适用于生产
- 带有嵌套子级的React Router
- 使用React Router进行服务器渲染时如何避免localStorage ReferenceError
- React-Router RouteHandler Undefined
- React Router和React Intl:有没有更好的方法来动态加载翻译's路线
- this.props.history已被弃用(react router)
- React-Redux React-router Store 在 props 中不可用
- 重定向到在 React-router 2 中以编程方式重定向到页面
- react-router:如何禁用(如果它处于活动状态)