react-router如何监听路由改变
监听路由改变,触发相应事件
话不多说,直接上代码
// 路由改变const history = useHistory();useEffect(() => { const unListen = history?.listen(() => { console.log('onRouterChange') }); return () => { unListen?.(); }}, [history])监听路由改变,触发相应事件
话不多说,直接上代码
// 路由改变const history = useHistory();useEffect(() => { const unListen = history?.listen(() => { console.log('onRouterChange') }); return () => { unListen?.(); }}, [history])