原先dva项目升级至2.0后,配置路由报错

import React from 'react'
import PropTypes from 'prop-types'
import { Switch, Route, Redirect, routerRedux } from 'dva/router'
import dynamic from 'dva/dynamic'
import App from 'routes/app'

const { ConnectedRouter } = routerRedux

const Routers = function ({ history, app }) {
const error = dynamic({

app,
component: () => import('./routes/error'),

})
const routes = [

{
  path: '/show',
  models: () => [import('./models/data')],
  component: () => import('./routes/Show'),
}, {
  path: '/login',
  models: () => [import('./models/app')],
  component: () => import('./routes/Login'),
}, {
  path: '/integral',
  models: () => [import('./models/data')],
  component: () => import('./routes/integral/'),
},

]

return (

<ConnectedRouter history={history}>
  <App>
    <Switch>
      <Route exact path="/" render={() => (<Redirect to="/integral" />)} />
      {
        routes.map(({ path, ...dynamics }, key) => (
          <Route key={key}
            exact
            path={path}
            component={dynamic({
              app,
              ...dynamics,
            })}
          />
        ))
      }
      <Route component={error} />
    </Switch>
  </App>
</ConnectedRouter>

)
}

Routers.propTypes = {
history: PropTypes.object,
app: PropTypes.object,
}

export default Routers

====================================================================
图片描述

阅读 3.5k
1 个回答

未配置webpackConfig.resolve.alias,已解决

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题