【发布时间】:2015-06-15 15:37:53
【问题描述】:
我有以下:
<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 中呈现。
我希望“app”路由中的 DefaultRoute 指向“searchDashboard”路由。这是我可以用 React Router 做的事情,还是我应该为此使用普通的 Javascript(用于页面重定向)?
基本上,如果用户转到主页,我想将他们发送到搜索仪表板。所以我想我正在寻找一个等同于window.location.replace("mygreathostname.com/#/dashboards/searchDashboard"); 的 React Router 功能
【问题讨论】:
-
你试过用 Redirect 代替 DefaultRoute 吗?
-
@JonatanLundqvistMedén 这正是我想要的,谢谢!把它写成答案,我会把它标记为正确的。抱歉延迟回复。
标签: javascript routes reactjs url-redirection react-router