使用 react-router-dom 重定向到第三方 URL [英] Redirect to third party url using react-router-dom
本文介绍了使用 react-router-dom 重定向到第三方 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我非常了解 react-router-dom 我想对组件进行条件渲染.如果使用未登录,则将他重定向到某个第三方 URL
I'm very much aware of the react-router-dom I want to do a conditional rendering of the component. If use is not logged in redirect him to some third party URL
例如,下面的代码看起来很整洁并且工作正常
for example, the below code looks neat and works fine
<Route exact path="/home" render={() => (
isLoggedIn() ? (
<Redirect to="/front"/>
) : (
<Home />
)
)}/>
让我们在上面的例子中说,如果我想将重定向到
https://www.google.com 我该怎么做?
Let's say in the above example if I want to redirect to
https://www.google.com how can I do it?
如果我写
<Redirect to="https://www.google.com"> it gives me error.
如何重定向到第三方网站?
How can I redirect to a third party website?
推荐答案
可以为外部 url 使用标签,
You can use a tag for external urls,
<a href='https://domain.extension/external-without-params'>external</a>
但你也可以提供这样的组件:
but also you can provide component like this:
<Route path='/external' component={() => { window.location = 'https://domain.extension/external-without-params'; return null;} }/>
这篇关于使用 react-router-dom 重定向到第三方 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文