首页 > 解决方案 > 路由重定向到反应路由器中陷入循环的外部链接

问题描述

从反应应用程序中,我正在调用带有反应路由器的外部链接,如下所示

<PrivateRoute exact path='/a/b' component={() => { 
                        window.location = `https://externallink/a/b`; 
                        return null;
                    }}/>

重定向正在工作,但它陷入了循环。它无限期地调用外部链接。我怎样才能停止循环。

标签: reactjsreact-router

解决方案


尝试这个

<PrivateRoute exact path='/a/b' component={() => { 
                        useEffect(()=>{
                        const redirectLink = `https://externallink/a/b`
                        window.location !== redirectLink 
                        && window.location = redirectLink
                        },[])
                        return null;
                    }}/>

推荐阅读