Commit 5a61434c authored by nikogu's avatar nikogu

fixed dynamic router

parent 44d2c7bb
import dynamic from 'dva/dynamic'; import dynamic from 'dva/dynamic';
// models
import UserModel from '../models/user';
import ChartModel from '../models/chart';
import MonitorModel from '../models/monitor';
import ProjectModel from '../models/project';
import ActivitiesModel from '../models/activities';
import FormModel from '../models/form';
import RuleModel from '../models/rule';
import ListModel from '../models/list';
import ProfileModel from '../models/profile';
import LoginModel from '../models/login';
import RegisterModel from '../models/register';
// components
import BasicLayout from '../layouts/BasicLayout';
import UserLayout from '../layouts/UserLayout';
import BlankLayout from '../layouts/BlankLayout';
import Analysis from '../routes/Dashboard/Analysis';
import Monitor from '../routes/Dashboard/Monitor';
import Workplace from '../routes/Dashboard/Workplace';
import BasicForm from '../routes/Forms/BasicForm';
import AdvancedForm from '../routes/Forms/AdvancedForm';
import StepForm from '../routes/Forms/StepForm';
import Step2 from '../routes/Forms/StepForm/Step2';
import Step3 from '../routes/Forms/StepForm/Step3';
import TableList from '../routes/List/TableList';
import BasicList from '../routes/List/BasicList';
import CardList from '../routes/List/CardList';
import CoverCardList from '../routes/List/CoverCardList';
import FilterCardList from '../routes/List/FilterCardList';
import SearchList from '../routes/List/SearchList';
import BasicProfile from '../routes/Profile/BasicProfile';
import AdvancedProfile from '../routes/Profile/AdvancedProfile';
import Success from '../routes/Result/Success';
import Error from '../routes/Result/Error';
import Exception403 from '../routes/Exception/403';
import Exception404 from '../routes/Exception/404';
import Exception500 from '../routes/Exception/500';
import Login from '../routes/User/Login';
import Register from '../routes/User/Register';
import RegisterResult from '../routes/User/RegisterResult';
// wrapper of dynamic // wrapper of dynamic
const dy = (app, models, component) => dynamic({ const dynamicWrapper = (app, models, component) => dynamic({
app, app,
models: () => models, models: () => models.map(m => import(`../models/${m}.js`)),
component: () => component, component: () => component,
}); });
// nav data // nav data
export const getNavData = app => [ export const getNavData = app => [
{ {
component: dy(app, [UserModel], BasicLayout), component: dynamicWrapper(app, ['user'], import('../layouts/BasicLayout')),
layout: 'BasicLayout', layout: 'BasicLayout',
name: '首页', // for breadcrumb name: '首页', // for breadcrumb
path: '/', path: '/',
...@@ -71,17 +23,17 @@ export const getNavData = app => [ ...@@ -71,17 +23,17 @@ export const getNavData = app => [
{ {
name: '分析页', name: '分析页',
path: 'analysis', path: 'analysis',
component: dy(app, [ChartModel], Analysis), component: dynamicWrapper(app, ['chart'], import('../routes/Dashboard/Analysis')),
}, },
{ {
name: '监控页', name: '监控页',
path: 'monitor', path: 'monitor',
component: dy(app, [MonitorModel], Monitor), component: dynamicWrapper(app, ['monitor'], import('../routes/Dashboard/Monitor')),
}, },
{ {
name: '工作台', name: '工作台',
path: 'workplace', path: 'workplace',
component: dy(app, [ProjectModel, ActivitiesModel, ChartModel], Workplace), component: dynamicWrapper(app, ['project', 'activities', 'chart'], import('../routes/Dashboard/Workplace')),
}, },
], ],
}, },
...@@ -93,30 +45,31 @@ export const getNavData = app => [ ...@@ -93,30 +45,31 @@ export const getNavData = app => [
{ {
name: '基础表单', name: '基础表单',
path: 'basic-form', path: 'basic-form',
component: dy(app, [FormModel], BasicForm), component: dynamicWrapper(app, ['form'], import('../routes/Forms/BasicForm')),
}, },
{ {
name: '分步表单', name: '分步表单',
path: 'step-form', path: 'step-form',
component: dy(app, [FormModel], StepForm), component: dynamicWrapper(app, ['form'], import('../routes/Forms/StepForm')),
children: [ children: [
{ {
path: 'confirm', path: 'confirm',
component: dy(app, [FormModel], Step2), component: dynamicWrapper(app, ['form'], import('../routes/Forms/StepForm/Step2')),
}, },
{ {
path: 'result', path: 'result',
component: dy(app, [FormModel], Step3), component: dynamicWrapper(app, ['form'], import('../routes/Forms/StepForm/Step3')),
}, },
], ],
}, },
{ {
name: '高级表单', name: '高级表单',
path: 'advanced-form', path: 'advanced-form',
component: dy(app, [FormModel], AdvancedForm), component: dynamicWrapper(app, ['form'], import('../routes/Forms/AdvancedForm')),
}, },
], ],
}, { },
{
name: '列表页', name: '列表页',
path: 'list', path: 'list',
icon: 'table', icon: 'table',
...@@ -124,32 +77,32 @@ export const getNavData = app => [ ...@@ -124,32 +77,32 @@ export const getNavData = app => [
{ {
name: '查询表格', name: '查询表格',
path: 'table-list', path: 'table-list',
component: dy(app, [RuleModel], TableList), component: dynamicWrapper(app, ['rule'], import('../routes/List/TableList')),
}, },
{ {
name: '标准列表', name: '标准列表',
path: 'basic-list', path: 'basic-list',
component: dy(app, [ListModel], BasicList), component: dynamicWrapper(app, ['list'], import('../routes/List/BasicList')),
}, },
{ {
name: '卡片列表', name: '卡片列表',
path: 'card-list', path: 'card-list',
component: dy(app, [ListModel], CardList), component: dynamicWrapper(app, ['list'], import('../routes/List/CardList')),
}, },
{ {
name: '搜索列表(项目)', name: '搜索列表(项目)',
path: 'cover-card-list', path: 'cover-card-list',
component: dy(app, [ListModel], CoverCardList), component: dynamicWrapper(app, ['list'], import('../routes/List/CoverCardList')),
}, },
{ {
name: '搜索列表(应用)', name: '搜索列表(应用)',
path: 'filter-card-list', path: 'filter-card-list',
component: dy(app, [ListModel], FilterCardList), component: dynamicWrapper(app, ['list'], import('../routes/List/FilterCardList')),
}, },
{ {
name: '搜索列表(文章)', name: '搜索列表(文章)',
path: 'search', path: 'search',
component: dy(app, [ListModel], SearchList), component: dynamicWrapper(app, ['list'], import('../routes/List/SearchList')),
}, },
], ],
}, },
...@@ -161,12 +114,12 @@ export const getNavData = app => [ ...@@ -161,12 +114,12 @@ export const getNavData = app => [
{ {
name: '基础详情页', name: '基础详情页',
path: 'basic', path: 'basic',
component: dy(app, [ProfileModel], BasicProfile), component: dynamicWrapper(app, ['profile'], import('../routes/Profile/BasicProfile')),
}, },
{ {
name: '高级详情页', name: '高级详情页',
path: 'advanced', path: 'advanced',
component: dy(app, [ProfileModel], AdvancedProfile), component: dynamicWrapper(app, ['profile'], import('../routes/Profile/AdvancedProfile')),
}, },
], ],
}, },
...@@ -178,12 +131,12 @@ export const getNavData = app => [ ...@@ -178,12 +131,12 @@ export const getNavData = app => [
{ {
name: '成功', name: '成功',
path: 'success', path: 'success',
component: dy(app, [], Success), component: dynamicWrapper(app, [], import('../routes/Result/Success')),
}, },
{ {
name: '失败', name: '失败',
path: 'fail', path: 'fail',
component: dy(app, [], Error), component: dynamicWrapper(app, [], import('../routes/Result/Error')),
}, },
], ],
}, },
...@@ -195,24 +148,24 @@ export const getNavData = app => [ ...@@ -195,24 +148,24 @@ export const getNavData = app => [
{ {
name: '403', name: '403',
path: '403', path: '403',
component: dy(app, [], Exception403), component: dynamicWrapper(app, [], import('../routes/Exception/403')),
}, },
{ {
name: '404', name: '404',
path: '404', path: '404',
component: dy(app, [], Exception404), component: dynamicWrapper(app, [], import('../routes/Exception/404')),
}, },
{ {
name: '500', name: '500',
path: '500', path: '500',
component: dy(app, [], Exception500), component: dynamicWrapper(app, [], import('../routes/Exception/500')),
}, },
], ],
}, },
], ],
}, },
{ {
component: dy(app, [], UserLayout), component: dynamicWrapper(app, [], import('../layouts/UserLayout')),
path: '/user', path: '/user',
layout: 'UserLayout', layout: 'UserLayout',
children: [ children: [
...@@ -224,24 +177,24 @@ export const getNavData = app => [ ...@@ -224,24 +177,24 @@ export const getNavData = app => [
{ {
name: '登录', name: '登录',
path: 'login', path: 'login',
component: dy(app, [LoginModel], Login), component: dynamicWrapper(app, ['login'], import('../routes/User/Login')),
}, },
{ {
name: '注册', name: '注册',
path: 'register', path: 'register',
component: dy(app, [RegisterModel], Register), component: dynamicWrapper(app, ['register'], import('../routes/User/Register')),
}, },
{ {
name: '注册结果', name: '注册结果',
path: 'register-result', path: 'register-result',
component: dy(app, [], RegisterResult), component: dynamicWrapper(app, [], import('../routes/User/RegisterResult')),
}, },
], ],
}, },
], ],
}, },
{ {
component: dy(app, [], BlankLayout), component: dynamicWrapper(app, [], import('../layouts/BlankLayout')),
layout: 'BlankLayout', layout: 'BlankLayout',
children: { children: {
name: '使用文档', name: '使用文档',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment