加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – 将react-router v3迁移到v4

发布时间:2020-12-15 16:18:22 所属栏目:百科 来源:网络整理
导读:我目前正在尝试将react-react从v3迁移到v4,但我无法完全掌握新概念,我的旧反应路由器v3代码看起来像这样,有人可以看看并给我一些提示吗? 谢谢! Router history={ browserHistory } Route path="/" component={ App } IndexRoute name="index" component={
我目前正在尝试将react-react从v3迁移到v4,但我无法完全掌握新概念,我的旧反应路由器v3代码看起来像这样,有人可以看看并给我一些提示吗?

谢谢!

<Router history={ browserHistory }>
     <Route path="/" component={ App }>
       <IndexRoute name="index" component={ Index } />
       <Route name="documents" path="/documents" component={ Documents } onEnter={ authenticate } />
       <Route name="newDocument" path="/documents/new" component={ NewDocument } onEnter={ authenticate } />
       <Route name="editDocument" path="/documents/:_id/edit" component={ EditDocument } onEnter={ authenticate } />
       <Route name="viewDocument" path="/documents/:_id" component={ ViewDocument } onEnter={ authenticate } />
       <Route name="login" path="/login" component={ Login } />
       <Route name="recover-password" path="/recover-password" component={ RecoverPassword } />
       <Route name="reset-password" path="/reset-password/:token" component={ ResetPassword } />
       <Route name="signup" path="/signup" component={ Signup } />
       <Route path="*" component={ NotFound } />
     </Route>
   </Router>

解决方法

不要筑巢路线.

保留这一部分

<Router history={ browserHistory }>
  <Route path="/" component={ App } />
</Router>

并将所有嵌套移动到< App /> (见here). react-router-v4也没有< IndexRoute />的概念. (见here).

看看documentation,真是不可思议.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读