react-router如何监听路由改变

36 字
1 分钟
react-router如何监听路由改变

话不多说,直接上代码

// 路由改变
const history = useHistory();
useEffect(() => {
const unListen = history?.listen(() => {
console.log('onRouterChange')
});
return () => {
unListen?.();
}
}, [history])
react-router如何监听路由改变
https://wangxiang.website/posts/前端框架/react-router-change/
作者
翔子
发布于
2022-08-16
许可协议
CC BY-NC-SA 4.0
Profile Image of the Author
翔子
前端开发工程师
公告
博客已从 VitePress 迁移到 Astro + Firefly 主题,223 篇文章全部保留。
音乐
封面

音乐

暂未播放

0:00 0:00
暂无歌词
分类
标签
站点统计
文章
221
分类
9
标签
28
总字数
411,914
运行时长
0
最后活动
0 天前

文章目录