- 項目目錄
- eslint規範
- 路由優化
- /src/router.js 類vue的方式定義路由,dynamic做路由懶加載
import { Router, Route, Switch } from 'dva/router';
import dynamic from 'dva/dynamic' // 路由和models懶加載,按需加載
import routes from './routes' // 路由的進一步抽離,抽離之後這個文件就不在需要更改了
function RouterConfig({ history, app }) {
return (
<Router history={history}>
<Switch>
{
routes.map((item, key) => {
return <Route key={key} path={item.path} exact={item.exact} component={dynamic({
app,
component: item.component,
models: item.models
})} />
})
}
</Switch>
</Router>
)
}
export default RouterConfig
-
- 同時也有./routes的代碼
const routes = [
{
path: '/', // 首頁
exact: true,
component: () => import('./home/index.js'),
models: () => [import('../models/home')]
}
]
export default routes