退出反应后如何重定向到主页(在jsx中) [英] How to redirect to home page(in jsx) after logout in react
本文介绍了退出反应后如何重定向到主页(在jsx中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<li>
<a href="homepage.jsx">
<i className="fa fa-sign-out pull-right"></i>
Log Out
</a>
</li>
我在 homepage.jsx
中有主页组件,点击 logout
后,我需要转到主页组件.
I am having homepage component in homepage.jsx
, after clicking on logout
i need to go to homepage component.
帮我解决这个问题.
推荐答案
你正在使用 react-router
,所以不要使用 a
和 href
使用Link
,这样写:
You are using react-router
, so instead of using a
and href
use Link
, write it like this:
<li>
<Link to="/">
<i className="fa fa-sign-out pull-right"></i>
Log Out
</Link>
</li>
由于主页组件是您的indexroute
,因此导航到/
将呈现
它.
Since Homepage component is your indexroute
, so navigation to /
will render
it.
如果您想在任何函数内动态导航,请查看此答案:
If you want to navigate dynamically means inside any function, then check this answer:
这篇关于退出反应后如何重定向到主页(在jsx中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文