react-router如何监听路由改变
正在加载今日诗词....
2022-08-15

话不多说,直接上代码

// 路由改变
const history = useHistory();
useEffect(() => {
  const unListen = history?.listen(() => {
    console.log('onRouterChange')
  });
  return () => {
    unListen?.();
  }
}, [history])

京ICP备2022027737号
Copyright © 2022 - present @wangxiang

  • ☀️
  • 🌑