Dva: router should be function, but got object

Created on 18 Oct 2017  ·  9Comments  ·  Source: dvajs/dva

Trying to use react-app-rewire and create-react-app (instructions followed from antd) with dva and dva-hmr

Without dva-hmr it works. Not sure exact which features dva-hmr adds.

Code to reproduce the issue: (请提供可复现的代码或者步骤)

https://github.com/andriijas/create-react-app-playground

Expected behavior: (预期的正常效果)

When running npm start it should work

Actual behavior: (实际效果)

Router gets function but might be wrapped in object perhaps thats why it breaks?

Versions of packages used: (哪个库的哪个版本出现的问题)

Check package.json in repo

bug

Most helpful comment

I found the solution.
In index.js, change app.router(require('./router')) into something like that:

import router from './router'
app.router(router)

All 9 comments

+1

I found the solution.
In index.js, change app.router(require('./router')) into something like that:

import router from './router'
app.router(router)

@gaohailang it works like that if i disable dva hmr plugin but with plugin enabled, it doesnt work

Thanks for report, I will fix this problem in babel-plugin-dva-hmr.

Thanks. I got it working with require("./router'").default but hmr did not work, page reload when I save footer.

Sent from my iPhone

On 4 Nov 2017, at 14:59, chencheng (云谦) notifications@github.com wrote:

Thanks for report, I will fix this problem in babel-plugin-dva-hmr.


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or mute the thread.

It's fixed, try [email protected] .

在 production build里,这个问题好像没有解决,在user-dashboard这个例子生成后,方服务器会报这个错误。

在 create-react-app创建的项目中使用,依然会报错

1572

Was this page helpful?
0 / 5 - 0 ratings