@umijs/plugins 4.0.0-rc.7 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/access.js CHANGED
@@ -1,18 +1,12 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
4
  };
11
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_1 = __importDefault(require("fs"));
12
7
  const path_1 = require("path");
13
8
  const withTmpPath_1 = require("./utils/withTmpPath");
14
9
  exports.default = (api) => {
15
- // TODO: route access
16
10
  api.describe({
17
11
  config: {
18
12
  schema(joi) {
@@ -21,19 +15,29 @@ exports.default = (api) => {
21
15
  },
22
16
  enableBy: api.EnableBy.config,
23
17
  });
24
- api.onGenerateFiles(() => __awaiter(void 0, void 0, void 0, function* () {
18
+ api.onGenerateFiles(async () => {
19
+ // allow enable access without access file
20
+ const hasAccessFile = ['js', 'jsx', 'ts', 'tsx'].some((ext) => fs_1.default.existsSync((0, path_1.join)(api.paths.absSrcPath, `access.${ext}`)));
25
21
  // runtime.tsx
26
22
  api.writeTmpFile({
27
23
  path: 'runtime.tsx',
28
24
  content: `
29
- import React from 'react';
30
- import accessFactory from '@/access';
25
+ import React from 'react';${hasAccessFile
26
+ ? `
27
+ import accessFactory from '@/access'
31
28
  import { useModel } from '@@/plugin-model';
29
+ `
30
+ : ''}
32
31
  import { AccessContext } from './context';
33
32
 
34
- function Provider(props) {
33
+ function Provider(props) {${hasAccessFile
34
+ ? `
35
35
  const { initialState } = useModel('@@initialState');
36
36
  const access = React.useMemo(() => accessFactory(initialState), [initialState]);
37
+ `
38
+ : `
39
+ const access = {};
40
+ `}
37
41
  return (
38
42
  <AccessContext.Provider value={access}>
39
43
  { props.children }
@@ -46,16 +50,74 @@ export function accessProvider(container) {
46
50
  }
47
51
  `,
48
52
  });
49
- // index.ts
53
+ // index.tsx
50
54
  api.writeTmpFile({
51
- path: 'index.ts',
55
+ path: 'index.tsx',
52
56
  content: `
53
- import React from 'react';
57
+ import React, { PropsWithChildren } from 'react';
54
58
  import { AccessContext } from './context';
59
+ import type { IRoute } from 'umi';
55
60
 
56
61
  export const useAccess = () => {
57
62
  return React.useContext(AccessContext);
58
63
  };
64
+
65
+ export interface AccessProps {
66
+ accessible: boolean;
67
+ fallback?: React.ReactNode;
68
+ }
69
+ export const Access: React.FC<PropsWithChildren<AccessProps>> = (props) => {
70
+ if (process.env.NODE_ENV === 'development' && typeof props.accessible !== 'boolean') {
71
+ throw new Error('[access] the \`accessible\` property on <Access /> should be a boolean');
72
+ }
73
+
74
+ return <>{ props.accessible ? props.children : props.fallback }</>;
75
+ };
76
+
77
+ export const useAccessMarkedRoutes = (routes: IRoute[]) => {
78
+ const access = useAccess();
79
+ const markdedRoutes: IRoute[] = React.useMemo(() => {
80
+ const process = (route, parentAccessCode) => {
81
+ const accessCode = route.access || parentAccessCode;
82
+
83
+ // set default status
84
+ route.unaccessible = ${api.config.access.strictMode ? 'true' : 'false'};
85
+
86
+ // check access code
87
+ if (typeof accessCode === 'string') {
88
+ const detector = access[accessCode];
89
+
90
+ if (typeof detector === 'function') {
91
+ route.unaccessible = !detector(route);
92
+ } else if (typeof detector === 'boolean') {
93
+ route.unaccessible = !detector;
94
+ } else if (typeof detector === 'undefined') {
95
+ route.unaccessible = true;
96
+ }
97
+ }
98
+
99
+ // check children access code
100
+ if (route.children?.length) {
101
+ const isNoAccessibleChild = !route.children.reduce((hasAccessibleChild, child) => {
102
+ process(child, accessCode);
103
+
104
+ return hasAccessibleChild || !child.unaccessible;
105
+ }, false);
106
+
107
+ // make sure parent route is unaccessible if all children are unaccessible
108
+ if (isNoAccessibleChild) {
109
+ route.unaccessible = true;
110
+ }
111
+ }
112
+
113
+ return route;
114
+ }
115
+
116
+ return routes.map(route => process(route));
117
+ }, [routes.length]);
118
+
119
+ return markdedRoutes;
120
+ }
59
121
  `,
60
122
  });
61
123
  // context.ts
@@ -66,7 +128,7 @@ import React from 'react';
66
128
  export const AccessContext = React.createContext<any>(null);
67
129
  `,
68
130
  });
69
- }));
131
+ });
70
132
  api.addRuntimePlugin(() => {
71
133
  return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
72
134
  });
package/dist/analytics.js CHANGED
@@ -20,7 +20,7 @@ exports.default = (api) => {
20
20
  return `
21
21
  (function() {
22
22
  var hm = document.createElement('script');
23
- hm.src = 'https://hm.baidu.com/hm.js?${code}';
23
+ hm.src = '//hm.baidu.com/hm.js?${code}';
24
24
  var s = document.getElementsByTagName('script')[0];
25
25
  s.parentNode.insertBefore(hm, s);
26
26
  })();
package/dist/antd.js CHANGED
@@ -30,7 +30,12 @@ exports.default = (api) => {
30
30
  });
31
31
  },
32
32
  },
33
- enableBy: api.EnableBy.config,
33
+ enableBy({ userConfig }) {
34
+ // 由于本插件有 api.modifyConfig 的调用,以及 Umi 框架的限制
35
+ // 在其他插件中通过 api.modifyDefaultConfig 设置 antd 并不能让 api.modifyConfig 生效
36
+ // 所以这里通过环境变量来判断是否启用
37
+ return process.env.UMI_PLUGIN_ANTD_ENABLE || userConfig.antd;
38
+ },
34
39
  });
35
40
  function checkPkgPath() {
36
41
  if (!pkgPath) {
@@ -48,17 +53,31 @@ exports.default = (api) => {
48
53
  });
49
54
  api.modifyConfig((memo) => {
50
55
  checkPkgPath();
56
+ const antd = memo.antd || {};
57
+ // defaultConfig 的取值在 config 之后,所以改用环境变量传默认值
58
+ if (process.env.UMI_PLUGIN_ANTD_ENABLE) {
59
+ const { defaultConfig } = JSON.parse(process.env.UMI_PLUGIN_ANTD_ENABLE);
60
+ Object.assign(antd, defaultConfig);
61
+ }
51
62
  // antd import
52
63
  memo.alias.antd = pkgPath;
53
64
  // moment > dayjs
54
- if (memo.antd.dayjs) {
65
+ if (antd.dayjs) {
55
66
  memo.alias.moment = (0, path_1.dirname)(require.resolve('dayjs/package.json'));
56
67
  }
57
68
  // dark mode & compact mode
58
- if (memo.antd.dark || memo.antd.compact) {
69
+ if (antd.dark || antd.compact) {
59
70
  const { getThemeVariables } = require('antd/dist/theme');
60
- memo.theme = Object.assign(Object.assign({}, getThemeVariables(memo.antd)), memo.theme);
71
+ memo.theme = {
72
+ ...getThemeVariables(antd),
73
+ ...memo.theme,
74
+ };
61
75
  }
76
+ // antd theme
77
+ memo.theme = {
78
+ 'root-entry-name': 'default',
79
+ ...memo.theme,
80
+ };
62
81
  return memo;
63
82
  });
64
83
  // babel-plugin-import
@@ -73,6 +92,7 @@ exports.default = (api) => {
73
92
  libraryDirectory: 'es',
74
93
  style: style === 'less' ? true : 'css',
75
94
  },
95
+ 'antd',
76
96
  ],
77
97
  ]
78
98
  : [];
@@ -84,6 +104,7 @@ exports.default = (api) => {
84
104
  api.writeTmpFile({
85
105
  path: `runtime.tsx`,
86
106
  content: plugin_utils_1.Mustache.render(`
107
+ import React from 'react';
87
108
  import { ConfigProvider, Modal, message, notification } from 'antd';
88
109
 
89
110
  export function rootContainer(container) {
package/dist/dva.js CHANGED
@@ -25,11 +25,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.getAllModels = exports.getModelUtil = void 0;
27
27
  const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
28
+ const utils_1 = require("@umijs/utils");
28
29
  const path_1 = require("path");
29
30
  const plugin_utils_1 = require("umi/plugin-utils");
30
31
  const modelUtils_1 = require("./utils/modelUtils");
31
32
  const withTmpPath_1 = require("./utils/withTmpPath");
32
- const utils_1 = require("@umijs/utils");
33
33
  exports.default = (api) => {
34
34
  const pkgPath = (0, path_1.join)(__dirname, '../libs/dva.ts');
35
35
  api.describe({
@@ -80,15 +80,22 @@ import dvaImmer, { enableES5, enableAllPlugins } from '${(0, utils_1.winPath)(re
80
80
  `
81
81
  : ''}
82
82
  import React, { useRef } from 'react';
83
- import { history } from 'umi';
83
+ import { history, ApplyPluginsType, useAppData } from 'umi';
84
84
  import { models } from './models';
85
85
 
86
86
  export function RootContainer(props: any) {
87
+ const { pluginManager } = useAppData();
87
88
  const app = useRef<any>();
89
+ const runtimeDva = pluginManager.applyPlugins({
90
+ key: 'dva',
91
+ type: ApplyPluginsType.modify,
92
+ initialValue: {},
93
+ });
88
94
  if (!app.current) {
89
95
  app.current = create(
90
96
  {
91
97
  history,
98
+ ...(runtimeDva.config || {}),
92
99
  },
93
100
  {
94
101
  initialReducer: {},
@@ -105,7 +112,10 @@ export function RootContainer(props: any) {
105
112
  ${((_d = (_c = api.config.dva) === null || _c === void 0 ? void 0 : _c.immer) === null || _d === void 0 ? void 0 : _d.enableES5) ? `enableES5();` : ''}
106
113
  ${((_f = (_e = api.config.dva) === null || _e === void 0 ? void 0 : _e.immer) === null || _f === void 0 ? void 0 : _f.enableAllPlugins) ? `enableAllPlugins();` : ''}
107
114
  for (const id of Object.keys(models)) {
108
- app.current.model(models[id].model);
115
+ app.current.model({
116
+ namespace: models[id].namespace,
117
+ ...models[id].model,
118
+ });
109
119
  }
110
120
  app.current.start();
111
121
  }
@@ -139,6 +149,7 @@ export { connect, useDispatch, useStore, useSelector } from 'dva';`,
139
149
  api.addRuntimePlugin(() => {
140
150
  return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
141
151
  });
152
+ api.addRuntimePluginKey(() => ['dva']);
142
153
  // dva list model
143
154
  api.registerCommand({
144
155
  name: 'dva',
@@ -14,7 +14,12 @@ exports.default = (api) => {
14
14
  });
15
15
  api.register({
16
16
  key: 'addExtraModels',
17
- fn: () => [(0, withTmpPath_1.withTmpPath)({ api, path: '@@initialState.ts' })],
17
+ fn: () => [
18
+ (0, withTmpPath_1.withTmpPath)({
19
+ api,
20
+ path: '@@initialState.ts#{"namespace":"@@initialState"}',
21
+ }),
22
+ ],
18
23
  });
19
24
  api.addRuntimePluginKey(() => ['getInitialState']);
20
25
  api.addRuntimePlugin(() => {
@@ -30,8 +35,8 @@ exports.default = (api) => {
30
35
  import React from 'react';
31
36
  import { useModel } from '@@/plugin-model';
32
37
  ${loading
33
- ? `import Loading from ${loading}`
34
- : `function Loading() { return <div>loading</div>; }`}
38
+ ? `import Loading from '${loading}'`
39
+ : `function Loading() { return <div />; }`}
35
40
  export default function InitialStateProvider(props: any) {
36
41
  const appLoaded = React.useRef(false);
37
42
  const { loading = false } = useModel("@@initialState") || {};
@@ -55,8 +60,10 @@ export default function InitialStateProvider(props: any) {
55
60
  import { useState, useEffect, useCallback } from 'react';
56
61
  import { getInitialState } from '@/app';
57
62
 
63
+ export type InitialStateType = Awaited<ReturnType<typeof getInitialState>> | undefined;
64
+
58
65
  const initState = {
59
- initialState: undefined,
66
+ initialState: undefined as InitialStateType,
60
67
  loading: true,
61
68
  error: undefined,
62
69
  };
@@ -71,8 +78,6 @@ export default () => {
71
78
  } catch (e) {
72
79
  setState((s) => ({ ...s, error: e, loading: false }));
73
80
  }
74
- // [?]
75
- // await sleep(10);
76
81
  }, []);
77
82
 
78
83
  const setInitialState = useCallback(async (initialState) => {
@@ -82,8 +87,6 @@ export default () => {
82
87
  }
83
88
  return { ...s, initialState, loading: false };
84
89
  });
85
- // [?]
86
- // await sleep(10)
87
90
  }, []);
88
91
 
89
92
  useEffect(() => {
@@ -107,7 +110,7 @@ export default () => ({ loading: false, refresh: () => {} })
107
110
  content: `
108
111
  import React from 'react';
109
112
  import Provider from './Provider';
110
- export function innerProvider(container) {
113
+ export function dataflowProvider(container) {
111
114
  return <Provider>{ container }</Provider>;
112
115
  }
113
116
  `,
package/dist/layout.js CHANGED
@@ -22,15 +22,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  const allIcons = __importStar(require("@ant-design/icons"));
30
- const assert_1 = __importDefault(require("assert"));
27
+ const fs_1 = require("fs");
31
28
  const path_1 = require("path");
32
29
  const plugin_utils_1 = require("umi/plugin-utils");
33
- const resolveProjectDep_1 = require("./utils/resolveProjectDep");
34
30
  const withTmpPath_1 = require("./utils/withTmpPath");
35
31
  exports.default = (api) => {
36
32
  api.describe({
@@ -43,11 +39,28 @@ exports.default = (api) => {
43
39
  },
44
40
  enableBy: api.EnableBy.config,
45
41
  });
46
- const pkgPath = (0, resolveProjectDep_1.resolveProjectDep)({
47
- pkg: api.pkg,
48
- cwd: api.cwd,
49
- dep: '@ant-design/pro-layout',
50
- }) || (0, path_1.dirname)(require.resolve('@ant-design/pro-layout/package.json'));
42
+ /**
43
+ * 优先去找 '@alipay/tech-ui',保证稳定性
44
+ */
45
+ const depList = ['@alipay/tech-ui', '@ant-design/pro-layout'];
46
+ const pkgHasDep = depList.find((dep) => {
47
+ var _a, _b;
48
+ const { pkg } = api;
49
+ if (((_a = pkg.dependencies) === null || _a === void 0 ? void 0 : _a[dep]) || ((_b = pkg.devDependencies) === null || _b === void 0 ? void 0 : _b[dep])) {
50
+ return true;
51
+ }
52
+ return false;
53
+ });
54
+ const getPkgPath = () => {
55
+ // 如果 layout 和 techui 至少有一个在,找到他们的地址
56
+ if (pkgHasDep &&
57
+ (0, fs_1.existsSync)((0, path_1.join)(api.cwd, 'node_modules', pkgHasDep, 'package.json'))) {
58
+ return (0, path_1.join)(api.cwd, 'node_modules', pkgHasDep);
59
+ }
60
+ // 如果项目中没有去找插件以来的
61
+ return (0, path_1.dirname)(require.resolve('@ant-design/pro-layout/package.json'));
62
+ };
63
+ const pkgPath = (0, plugin_utils_1.winPath)(getPkgPath());
51
64
  api.modifyAppData((memo) => {
52
65
  const version = require(`${pkgPath}/package.json`).version;
53
66
  memo.pluginLayout = {
@@ -57,8 +70,11 @@ exports.default = (api) => {
57
70
  return memo;
58
71
  });
59
72
  api.modifyConfig((memo) => {
60
- // import from @ant-design/pro-layout
61
- memo.alias['@ant-design/pro-layout'] = pkgPath;
73
+ // 只在没有自行依赖 @ant-design/pro-layout 或 @alipay/tech-ui 时
74
+ // 才使用插件中提供的 @ant-design/pro-layout
75
+ if (!pkgHasDep) {
76
+ memo.alias['@ant-design/pro-layout'] = pkgPath;
77
+ }
62
78
  return memo;
63
79
  });
64
80
  api.onGenerateFiles(() => {
@@ -67,17 +83,23 @@ exports.default = (api) => {
67
83
  api.writeTmpFile({
68
84
  path: 'Layout.tsx',
69
85
  content: `
70
- import { Link, useLocation, useNavigate, Outlet, useAppData, useRouteContext } from 'umi';
71
- import ProLayout, {
72
- PageLoading,
73
- } from '@ant-design/pro-layout';
86
+ import { Link, useLocation, useNavigate, Outlet, useAppData, useRouteData, matchRoutes } from 'umi';
87
+ import { useMemo } from 'react';
88
+ import {
89
+ ProLayout,
90
+ } from "${pkgPath || '@ant-design/pro-layout'}";
74
91
  import './Layout.less';
75
92
  import Logo from './Logo';
93
+ import Exception from './Exception';
76
94
  import { getRightRenderContent } from './rightRender';
77
95
  ${hasInitialStatePlugin
78
96
  ? `import { useModel } from '@@/plugin-model';`
79
97
  : 'const useModel = null;'}
80
-
98
+ ${api.config.access
99
+ ? `
100
+ import { useAccessMarkedRoutes } from '@@/plugin-access';
101
+ `.trim()
102
+ : 'const useAccessMarkedRoutes = (r) => r;'}
81
103
  ${api.config.locale
82
104
  ? `
83
105
  import { useIntl } from '@@/plugin-locale';
@@ -85,7 +107,7 @@ import { useIntl } from '@@/plugin-locale';
85
107
  : ''}
86
108
 
87
109
 
88
- export default () => {
110
+ export default (props: any) => {
89
111
  const location = useLocation();
90
112
  const navigate = useNavigate();
91
113
  const { clientRoutes, pluginManager } = useAppData();
@@ -108,9 +130,8 @@ const { formatMessage } = useIntl();
108
130
  ...initialInfo
109
131
  },
110
132
  });
111
- const route = clientRoutes.filter(r => {
112
- return r.id === 'ant-design-pro-layout';
113
- })[0];
133
+ const matchedRoute = useMemo(() => matchRoutes(clientRoutes, location.pathname).pop()?.route, [location.pathname]);
134
+ const [route] = useAccessMarkedRoutes(clientRoutes.filter(({ id }) => id === 'ant-design-pro-layout'));
114
135
  return (
115
136
  <ProLayout
116
137
  route={route}
@@ -132,7 +153,8 @@ const { formatMessage } = useIntl();
132
153
  }
133
154
  if (menuItemProps.path && location.pathname !== menuItemProps.path) {
134
155
  return (
135
- <Link to={menuItemProps.path} target={menuItemProps.target}>
156
+ // handle wildcard route path, for example /slave/* from qiankun
157
+ <Link to={menuItemProps.path.replace('/*', '')} target={menuItemProps.target}>
136
158
  {defaultDom}
137
159
  </Link>
138
160
  );
@@ -166,19 +188,45 @@ const { formatMessage } = useIntl();
166
188
  })
167
189
  }
168
190
  >
169
- <Outlet />
191
+ <Exception
192
+ route={matchedRoute}
193
+ notFound={runtimeConfig.notFound}
194
+ noAccessible={runtimeConfig.noAccessible}
195
+ >
196
+ {runtimeConfig.childrenRender
197
+ ? runtimeConfig.childrenRender(<Outlet />, props)
198
+ : <Outlet />
199
+ }
200
+ </Exception>
170
201
  </ProLayout>
171
202
  );
172
203
  }
173
204
  `,
205
+ });
206
+ // 写入类型, RunTimeLayoutConfig 是 app.tsx 中 layout 配置的类型
207
+ // 对于动态 layout 配置很有用
208
+ api.writeTmpFile({
209
+ path: 'index.ts',
210
+ content: `
211
+ import type { ProLayoutProps } from "${pkgPath || '@ant-design/pro-layout'}";
212
+ ${hasInitialStatePlugin
213
+ ? `import { Models } from '@@/plugin-model/useModel';
214
+ type InitDataType = Models<'@@initialState'>;
215
+ `
216
+ : 'type InitDataType = any;'}
217
+
218
+ export type RunTimeLayoutConfig = (
219
+ initData: InitDataType,
220
+ ) => BasicLayoutProps & {
221
+ childrenRender?: (dom: JSX.Element, props: ProLayoutProps) => React.ReactNode,
222
+ unAccessible?: JSX.Element,
223
+ noFound?: JSX.Element,
224
+ };`,
174
225
  });
175
226
  const iconsMap = Object.keys(api.appData.routes).reduce((memo, id) => {
176
227
  const { icon } = api.appData.routes[id];
177
228
  if (icon) {
178
229
  const upperIcon = plugin_utils_1.lodash.upperFirst(plugin_utils_1.lodash.camelCase(icon));
179
- (0, assert_1.default)(
180
- // @ts-ignore
181
- allIcons[upperIcon] || allIcons[`${upperIcon}Outlined`], `Icon ${upperIcon} is not found`);
182
230
  // @ts-ignore
183
231
  if (allIcons[upperIcon]) {
184
232
  memo[upperIcon] = true;
@@ -223,7 +271,9 @@ export function patchRoutes({ routes }) {
223
271
  const { icon } = routes[key];
224
272
  if (icon && typeof icon === 'string') {
225
273
  const upperIcon = formatIcon(icon);
226
- routes[key].icon = React.createElement(icons[upperIcon] || icons[upperIcon + 'Outlined']);
274
+ if (icons[upperIcon] || icons[upperIcon + 'Outlined']) {
275
+ routes[key].icon = React.createElement(icons[upperIcon] || icons[upperIcon + 'Outlined']);
276
+ }
227
277
  }
228
278
  });
229
279
  }
@@ -468,6 +518,43 @@ const LogoIcon: React.FC = () => {
468
518
  export default LogoIcon;
469
519
  `,
470
520
  });
521
+ api.writeTmpFile({
522
+ path: 'Exception.tsx',
523
+ content: `
524
+ import React from 'react';
525
+ import { history, type IRoute } from 'umi';
526
+ import { Result, Button } from 'antd';
527
+
528
+ const Exception: React.FC<{
529
+ children: React.ReactNode;
530
+ route?: IRoute;
531
+ notFound?: React.ReactNode;
532
+ noAccessible?: React.ReactNode;
533
+ }> = (props) => (
534
+ // render custom 404
535
+ (!props.route && props.notFound) ||
536
+ // render custom 403
537
+ (props.route.unaccessible && props.noAccessible) ||
538
+ // render default exception
539
+ ((!props.route || props.route.unaccessible) && (
540
+ <Result
541
+ status={props.route ? '403' : '404'}
542
+ title={props.route ? '403' : '404'}
543
+ subTitle={props.route ? '抱歉,你无权访问该页面' : '抱歉,你访问的页面不存在'}
544
+ extra={
545
+ <Button type="primary" onClick={() => history.push('/')}>
546
+ 返回首页
547
+ </Button>
548
+ }
549
+ />
550
+ )) ||
551
+ // normal render
552
+ props.children
553
+ );
554
+
555
+ export default Exception;
556
+ `,
557
+ });
471
558
  });
472
559
  api.addLayouts(() => {
473
560
  return [