#2501·dva

dva subscriptions不生效

Author: hackerainCreated Oct 24, 2022Updated Dec 21, 2022

What happens?

所有介绍dva subscription使用方法的文档,包括官网,都是类似下面这种例子:

app.model({
  subscriptions: {
    setup({ dispatch, history }) {
      console.log('xxxx1');
      history.listen(({ pathname }) => {
        console.log('xxxx2');
        if (pathname === '/users') {
          console.log('xxxx3');
          dispatch({
            type: 'users/fetch',
          });
        }
      });
    },
  },
});

但是在umi 4.x版本下,却怎么也不生效,加上上面的console.log发现,只能打出来xxxx1,但是xxxx2和3始终没有触发。

相关环境信息

  • Umi 版本:4.0.24
  • Node 版本
  • 操作系统