A clear and concise description of what the bug is.
当我安装了 "dva": "2.6.0-beta.4",版本后,打开项目,我的console抛出了两个警告
Warning: Please userequire("dva").routerinstead ofrequire("dva/router"). Support for the latter will be removed in the next major release.
Warning: Failed prop type: Invalid propcomponentof typeobjectsupplied toRoute, expectedfunction.
in Route (at router.jsx:14)
in DvaRoot
我该如何解决?我是从 "dva": "^2.4.1",版本升级到 "dva": "2.6.0-beta.4"版本的,之前2.4.1版本也有报警告的问题
Provide a mini GitHub repository which can reproduce the issue.
Useyarn create umi, selectapp, choosedva, then upload to your GitHub
Steps to reproduce the behavior:
1.
2.
Expected behavior
1.
2.
这样用,beta 版的 dva 推荐用 esm 格式,
import { router } from 'dva';
@sorrycc withRouter、Switch、Route、routerRedux这些怎么引入?
umi里也有这个报错
@sorrycc withRouter、Switch,、Route、routerRedux这些怎么引入?
import {Route,Switch,Redirect} from 'dva/router';
import { routerRedux } from 'dva/router'
我的项目里面是这样引入的,在但是在dva 2.4.1还是会有如下警告
index.js:1446 Warning: Please userequire("history").createHashHistoryinstead ofrequire("history/createHashHistory"). Support for the latter will be removed in the next major release.
在 2.6.0-beta.4 版本里面会有标题上面的警告
@sorrycc withRouter、Switch,、Route、routerRedux这些怎么引入?
import {Route,Switch,Redirect} from 'dva/router';
import { routerRedux } from 'dva/router'
我的项目里面是这样引入的,在但是在dva 2.4.1还是会有如下警告
index.js:1446 Warning: Please userequire("history").createHashHistoryinstead ofrequire("history/createHashHistory"). Support for the latter will be removed in the next major release.
在 2.6.0-beta.4 版本里面会有标题上面的警告
import { router } from 'dva'
const { Router, Switch, Route } = router
这样可以,但看着有点奇怪,不知道有没有更好的写法
另外有一个相关的问题请教一下,2.6.0-beta.4中抛出这个警告文件的warnAboutDeprecatedCJSRequire.js,
中间有函数在ie11(更老应该也是)中好像不兼容:

是函数最后一个参数后不能有逗号吗?
请问各位知道如何做到兼容ie11吗?
比如:
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';
个人偏向直接从react-router-dom引入,dva两行引入太麻烦
import { Router, Switch, Route } from 'react-router-dom';
Most helpful comment
require('dva/xxx') 报 Warning 怎么处理?
错误示例
比如:
原因
[email protected] beta 全部走 esm,然后项目中开 tree-shaking 把没用到的功能摇掉,推荐用
require('dva'),而不是require('dva/router'),所以给了警告。解决
修改代码,比如:
有个特殊的是 routerRedux,直接从 dva 下取就好了,
参考