【发布时间】:2018-01-01 16:11:37
【问题描述】:
我有2层路线,第一层是这样的
<BrowserRouter>
<div>
<AuthRoute></AuthRoute>
<Switch>
<Route path='/dashboard' component={Dashboard} />
</Switch>
</div>
</BrowserRouter>
在 AuthRoute 中我对 componentDidMount 进行了重定向
this.props.history.replace(/dashboard/redirected)
问题出在仪表板/索引中,这是我的第二级路由配置
<BrowserRouter>
<Switch>
<Route exact path='/dashboard' component={()=><h1>dashboard index</h1>} />
<Route exact path='/dashboard/somewhere' component={()=><h1>somewhere</h1>} />
<Route exact path='/dashboard/redirected' component={() => <h1>redirected</h1>} />
</Switch>
</BrowserRouter>
路由更改为/dashboard/redirect,但如果您刷新说/dashboard/somewhere 或/dashboard/,组件未呈现正确的路由
你可以在我设置https://codesandbox.io/s/v0v4qok38l的demo中更清楚地看到问题
【问题讨论】:
标签: javascript reactjs react-router