Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subscriptions的history.listen获取query,dva1是{},dva2是undefined #1218

Closed
zkeyword opened this issue Sep 13, 2017 · 7 comments
Closed

Comments

@zkeyword
Copy link

zkeyword commented Sep 13, 2017

subscriptions: {
        setup({ dispatch, history }) {
            return history.listen(({ pathname, query }) => {
                if (pathname === '/device') {
                    console.log(query)
                    dispatch({ type: 'list', payload: query })
                }
            })
        }
    }
@neewbee
Copy link

neewbee commented Sep 13, 2017

react-router v4 use search

@jdwdw
Copy link

jdwdw commented Sep 14, 2017

@zkeyword 按照Demo 可以这样

  subscriptions: {
    setup({ dispatch, history }) {
      return history.listen(({ pathname, search }) => {
        const query = queryString.parse(search);
        if (pathname === '/users') {
          dispatch({ type: 'fetch', payload: query });
        }
      });
    },
  },

@zkeyword
Copy link
Author

search 获取过来是 空字符

@jdwdw
Copy link

jdwdw commented Sep 14, 2017

@zkeyword search 属性是一个可读可写的字符串,可设置或返回当前 URL 的查询部分(问号 ? 之后的部分)。 没有源码不知到具体原因,可能是你当前的 url 没有查询部分。(就是问号?......)

@sorrycc
Copy link
Member

sorrycc commented Sep 15, 2017

参考 sorrycc/blog#48 的 break change 部分,history 的 location 属性上不再包含 query。

image

@sorrycc sorrycc closed this as completed Sep 15, 2017
@SunShinewyf
Copy link

@zkeyword 在 使用 routerRedux 进行 push 的时候,应该按照如下的写法:

       routerRedux.push({
        pathname: "/user",
        search: "?page=" + page
      })

然后在 model 中的监听可以按照 @jdwdw 那样写,search 就可以获取到了

@Ken-Scofield
Copy link

这边说的还是hash路由的方式吧, dva改为history路由的时候 history.listen回调参数怎么会变化呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants