原项目使用react-router 3.0,现在需要升级为4.0以上版本,在升级过程中发现报错,报错信息如下
warning.js
路由部分代码
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>,
不知道什么原因,求大神指点
v4是破坏性升级,意味着并不是直接把react-router版本号改成v4就可以了,你需要改写你原有的路由代码。比如v4中已经没有IndexRoute了。
可以看看我写的这篇v4的文章:https://segmentfault.com/a/11...。
然后看下React Router官网教程,对项目中的路由代码重构。