GithubHelp home page GithubHelp logo

Comments (14)

sorrycc avatar sorrycc commented on May 30, 2024 2
module.exports = require('react-router')
module.exports.routerRedux = require('react-router-redux')

这个方案 +1,命名想不好就先叫 routerRedux 吧。

from dva.

LeuisKen avatar LeuisKen commented on May 30, 2024 1

我现在也同意放在dva/router,我现在在想应该暴露哪些,感觉routerReducersyncHistoryWithStore都是没有必要暴露出来的。

我想先过一遍react-routerreact-router-redux的文档,看看哪些API是必要的,合并成一个对外的dva/router

from dva.

sorrycc avatar sorrycc commented on May 30, 2024

是指 push, replace 这些吗?

from dva.

LeuisKen avatar LeuisKen commented on May 30, 2024

嗯,以及LOCATION_CHANGE这些action

from dva.

sorrycc avatar sorrycc commented on May 30, 2024

方便的话,你发个 pr ?

from dva.

LeuisKen avatar LeuisKen commented on May 30, 2024

好的

from dva.

nikogu avatar nikogu commented on May 30, 2024

建议将 react-router-redux 跟 dva/router 一样,暴露出来就好了,然后自己在start里面去写middleware

from dva.

sorrycc avatar sorrycc commented on May 30, 2024

@nikogu react-router-redux 已经内置了的,只不过没有暴露接口。都是路由相关,放在 dva/router 感觉比较合适的。有其他更合适的 export 方式?

from dva.

nikogu avatar nikogu commented on May 30, 2024

@sorrycc 我感觉放到 dva/router 也挺好的,多暴露一个感觉也有点冗余,那么 @LeuisKen 这个调用api的方式,是不是可以『

import { routerMiddleware, push, browserHistory } from 'dva/router';

...
const App = app.start({
    middlewares: [routerMiddleware(browserHistory)]
});

// usage
dispatch(push('/foo'))

这样?

from dva.

nikogu avatar nikogu commented on May 30, 2024

@LeuisKen 我觉得我们可以不用关心该暴露哪些api,我们只需要把 react-routerreact-router-redux的merge到router里面一起返回就可以了,避免后面又有新增的api我们还得改,现在dva/router 就直接暴露了 module.exports = require('react-router');,现在就是多了一个 react-router-redux,你觉得如何,因为syncHistoryWithStore类似这样的api,暴露出来也没有关系

from dva.

LeuisKen avatar LeuisKen commented on May 30, 2024

那就merge吧,这样确实是简单粗暴

from dva.

sorrycc avatar sorrycc commented on May 30, 2024

先 reopen 了,pr 里写上 Close #23 自动关联上这里吧。

from dva.

nikogu avatar nikogu commented on May 30, 2024

@LeuisKen 你先看下怎么最合理,然后改下,提个pr 🐒

from dva.

LeuisKen avatar LeuisKen commented on May 30, 2024

对于如何优雅的引入react-router-redux遇到了一些困难

方案一:按 @nikogu 说的直接merge

实现一:

module.exports = { ...require('react-router'), ...require('react-router-redux') }

现在router.js并没有过babel,可以考虑在src中加入router.js或者修改配置来处理。或者用object-assign之类的包来处理,但dva引入这种包感觉不太合适。自己实现一个浅复制感觉也没太大意义。

实现二:

module.exports = require('react-router')
module.exports.routerRedux = require('react-router-redux')

我偏向这种方案,但是觉得很难找到一个合适的名字。。。

方案二:只引入需要的部分,我一开始的想法

module.exports = require('react-router');
module.exports.routerActions = require('react-router-redux').routerActions
module.exports.routerActions.CALL_HISTORY_METHOD = require('react-router-redux').routerActions.CALL_HISTORY_METHOD
module.exports.routerActions.LOCATION_CHANGE = require('react-router-redux').routerActions.LOCATION_CHANGE
module.exports.routerMileware  = require('react-router-redux').routerMiddleware

这样的问题 @nikogu 也说了,官方更新的话很不方便。

from dva.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.