react router利用history对象阻止链接跳转(实现路由守卫效果) 金牌发育路 2022-07-19 305 阅读1分钟 代码如下 useEffect(() => { return () => { const nextUrl = history?.location //组件卸载时监听history对象,可以获取将要跳转的链接nextUrl,利用goback方法跳回来 history.goBack() } }, [])