如何在React路由器中将DefaultRoute设置为另一个路由 [英] How to set the DefaultRoute to another Route in React Router
问题描述
我有以下内容:
<Route name="app" path="/" handler={App}>
<Route name="dashboards" path="dashboards" handler={Dashboard}>
<Route name="exploreDashboard" path="exploreDashboard" handler={ExploreDashboard} />
<Route name="searchDashboard" path="searchDashboard" handler={SearchDashboard} />
<DefaultRoute handler={DashboardExplain} />
</Route>
<DefaultRoute handler={SearchDashboard} />
</Route>
使用DefaultRoute时,SearchDashboard呈现错误,因为任何* Dashboard都需要在Dashboard中呈现。
When using the DefaultRoute, SearchDashboard renders incorrectly since any *Dashboard needs to rendered within Dashboard.
我想在appRoute中的DefaultRoute指向RoutesearchDashboard。这是我可以使用React Router做的事情,还是应该使用普通的Javascript(用于页面重定向)?
I would like for my DefaultRoute within the "app" Route to point to the Route "searchDashboard". Is this something that I can do with React Router, or should I use normal Javascript (for a page redirect) for this?
基本上,如果用户转到主页,我想将它们发送到搜索仪表板。所以我想我正在寻找相当于的反应路由器功能window.location.replace(mygreathostname.com /#/ dashboards / searchDashboard);
Basically, if the user goes to the home page I want to send them instead to the search dashboard. So I guess I'm looking for a React Router feature equivalent to window.location.replace("mygreathostname.com/#/dashboards/searchDashboard");
推荐答案
您可以使用Redirect而不是DefaultRoute
You can use Redirect instead of DefaultRoute
<Redirect from="/" to="searchDashboard" />
这篇关于如何在React路由器中将DefaultRoute设置为另一个路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!