使用umi框架的约定路由

 <Router>
 <Route path="/charts/type" exact component={ChartTypeSelect} />
 <Redirect exact from="/charts" to="/charts/type"/>
 <Route path="/charts/data" exact component={ChartDimensionsInput}/>
 <Route path="/charts/option" exact component={ChartOptionAdjust}/>
 </Router>

引入组件,其他略
import {withRouter} from 'react-router-dom'
跳转:

 this.props.history.push('/charts/data');

(后面export已经使用了withRouter)
发现地址栏地址发生变化,变为了.../charts/data,但页面并没有渲染相应组件。
参考:
react-router@4.2.0嵌套的路由用this.props.history.push()路由改变了但是页面却没更新
删掉外侧的Router标签
只保留Route:

 <Route path="/charts/type" exact component={ChartTypeSelect} />
 <Redirect exact from="/charts" to="/charts/type"/>
 <Route path="/charts/data" exact component={ChartDimensionsInput}/>
 <Route path="/charts/option" exact component={ChartOptionAdjust}/>

成功跳转


papermoon
6 声望0 粉丝