【问题标题】:What's the use of this statement: { router: routerReducer }这个语句有什么用:{ router: routerReducer }
【发布时间】:2018-03-25 21:45:37
【问题描述】:
我知道这是一个简单的问题,但我是初学者。
combineReducer这行有什么用
router: routerReducer
该行在此上下文中:
export default combineReducers({
article,
articleList,
auth,
router: routerReducer
});
【问题讨论】:
标签:
reactjs
ecmascript-6
redux
【解决方案1】:
实际上,它应该是最清晰的一行,因为您正在定义一个对象、一个键值对集合。其实你的代码相当于:
export default combineReducers({
article: article,
articleList: articleList,
auth: auth,
router: routerReducer
});
感谢 ES6 特性
【解决方案2】:
代码将一个 javascript 对象传递给 combineReducers() 函数。向对象添加元素有两种方式:
{item: item}
和
{item}
而后者是第一个的简写。仅当对象键和变量名称相同时,速记才有效。
代码也可以这样写:
{
article: article,
articleList: articleList,
auth: auth,
router: routerReducer
}