dva icon indicating copy to clipboard operation
dva copied to clipboard

routerRedux.push如何传递数组参数?

Open yinxuan1128 opened this issue 9 years ago • 2 comments

dispatch(routerRedux.push({ pathname: location.pathname, query: { ...value, searchTags:tags, page: 1, pageSize, }, })) 这里searchTags是一个数组,但是上面的写法不能正确获取结果,url上的参数显示是searchTags=XXX,如果把url参数改成searchTags[]=XXX就可以获得正确结果,那么怎么在query里面定义数组参数呢?我试着改成searchTags[]:tags,但是程序报错了

yinxuan1128 avatar Aug 13 '17 08:08 yinxuan1128

看了下源码,是用 query-string 进行转义的,但不清楚是否支持数组。https://github.com/ReactTraining/history/blob/44bc923/modules/useQueries.js#L9-L11

你可以自行用 query-string 转转看。

sorrycc avatar Aug 13 '17 23:08 sorrycc

@yinxuan1128 可以用

// 跳转
this.props.dispatch(routerRedux.push({
  pathname: '',
  state: { searchTags: [] },
}));
// 获取
this.props.location.state;

yozman avatar Dec 06 '17 01:12 yozman