react-router3.0升级4的时候报错。

发布于 2022-09-05 23:21:08 字数 1219 浏览 19 评论 0

原项目使用react-router 3.0,现在需要升级为4.0以上版本,在升级过程中发现报错,报错信息如下

clipboard.png
warning.js

clipboard.png
路由部分代码

import React from 'react';
import ReactDOM from 'react-dom';
import { Route, Link ,HashRouter,hashHistory,IndexRoute } from 'react-router-dom';
<HashRouter>

    {/*Pages*/}
    <Route path="/" component={BasePage}>
        <IndexRoute component={Login} />
        <Route path="login" component={Login}/>
        <Route path="register" component={Register}/>
        <Route path="recover" component={Recover}/>
        <Route path="code" component={VerifyCode}/>
        <Route path="newpassword" component={NewPassword}/>
        <Route path="notfound" component={NotFound}/>
        <Route path="error500" component={Error500}/>
        <Route path="maintenance" component={Maintenance}/>
    </Route>
</HashRouter>,

不知道什么原因,求大神指点

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

茶色山野 2022-09-12 23:21:09

v4是破坏性升级,意味着并不是直接把react-router版本号改成v4就可以了,你需要改写你原有的路由代码。比如v4中已经没有IndexRoute了。
可以看看我写的这篇v4的文章:https://segmentfault.com/a/11...
然后看下React Router官网教程,对项目中的路由代码重构。

纵山崖 2022-09-12 23:21:09
  1. 我大致看了下哦,你先去看文档,因为React-router v4 都没有 IndexRoute 组件了。你还在用啊~
  2. Route组件不能嵌套了

反正是一点一点都不一样了。建议不是必须 就别升级~~

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文