Dva: 引入dva,出现警告

Created on 28 Jun 2019  ·  2Comments  ·  Source: dvajs/dva

What happens?

仅仅在项目中引入dva就出现,如下警告

 Warning: Please use `require("history").createHashHistory` instead of `require("history/createHashHistory")`. Support for the latter will be removed in the next major release.

仓库地址
https://github.com/Tomny2016/react-dva-antd-project/blob/master/src/index.js

项目代码

import React from 'react';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';

import dva from 'dva';
// 创建应用

const app = dva()
// 注册视图
app.router (() => <App />);
// 启动应用
app.start ('#root');

serviceWorker.unregister ();

How To Reproduce

Steps to reproduce the behavior:
1.
2.

Expected behavior
1.
2.

Context

  • Dva Version:
  • Node Version:
  • Platform:

Most helpful comment

你这修复的是bate的版本,2.4.1不打算修复了吗?

All 2 comments

require('dva/xxx') 报 Warning 怎么处理?

错误示例

比如:

Warning: Please use require("dva").routerinstead ofrequire("dva/router"). Support for the latter will be removed in the next major release.
Warning: Please use `require("history").createHashHistory` instead of `require("history/createHashHistory")`. Support for the latter will be removed in the next major release.

原因

[email protected] beta 全部走 esm,然后项目中开 tree-shaking 把没用到的功能摇掉,推荐用 require('dva'),而不是 require('dva/router'),所以给了警告。

解决

修改代码,比如:

- import { Link, Switch } from 'dva/router';
+ import { router } from 'dva';
+ const { Link, Switch } = router;
- import dynamic from 'dva/dynamic';
+ import { dynamic } from 'dva';

有个特殊的是 routerRedux,直接从 dva 下取就好了,

- import { routerRedux } from 'dva/router';
+ import { routerRedux } from 'dva';

history 的同理,你应该会解决的。

参考

你这修复的是bate的版本,2.4.1不打算修复了吗?

Was this page helpful?
0 / 5 - 0 ratings