@umijs/renderer-react 3.5.22 → 3.5.25

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.
@@ -0,0 +1,34 @@
1
+ import { History, Location } from 'history-with-query';
2
+ import { FunctionComponent } from 'react';
3
+ import { match } from 'react-router-dom';
4
+ export interface IComponent extends FunctionComponent {
5
+ getInitialProps?: Function;
6
+ preload?: () => Promise<any>;
7
+ }
8
+ export interface IRoute {
9
+ path?: string;
10
+ exact?: boolean;
11
+ redirect?: string;
12
+ component?: IComponent | string;
13
+ routes?: IRoute[];
14
+ key?: any;
15
+ strict?: boolean;
16
+ sensitive?: boolean;
17
+ wrappers?: any[];
18
+ [k: string]: any;
19
+ }
20
+ export interface IRouteComponentProps<Params extends {
21
+ [K in keyof Params]?: string;
22
+ } = {}, Query extends {
23
+ [K in keyof Query]?: string;
24
+ } = {}> {
25
+ children: JSX.Element;
26
+ location: Location & {
27
+ query: Query;
28
+ };
29
+ route: IRoute;
30
+ routes: IRoute[];
31
+ history: History;
32
+ match: match<Params>;
33
+ }
34
+ export { default as renderRoutes } from './renderRoutes/renderRoutes';
package/dist/index.d.ts CHANGED
@@ -1,35 +1,2 @@
1
- import { History, Location } from 'history-with-query';
2
- import { FunctionComponent } from 'react';
3
- import { match } from 'react-router-dom';
4
- export interface IComponent extends FunctionComponent {
5
- getInitialProps?: Function;
6
- preload?: () => Promise<any>;
7
- }
8
- export interface IRoute {
9
- path?: string;
10
- exact?: boolean;
11
- redirect?: string;
12
- component?: IComponent | string;
13
- routes?: IRoute[];
14
- key?: any;
15
- strict?: boolean;
16
- sensitive?: boolean;
17
- wrappers?: any[];
18
- [k: string]: any;
19
- }
20
- export interface IRouteComponentProps<Params extends {
21
- [K in keyof Params]?: string;
22
- } = {}, Query extends {
23
- [K in keyof Query]?: string;
24
- } = {}> {
25
- children: JSX.Element;
26
- location: Location & {
27
- query: Query;
28
- };
29
- route: IRoute;
30
- routes: IRoute[];
31
- history: History;
32
- match: match<Params>;
33
- }
1
+ export * from './commonExports';
34
2
  export { default as renderClient } from './renderClient/renderClient';
35
- export { default as renderRoutes } from './renderRoutes/renderRoutes';
package/dist/index.esm.js CHANGED
@@ -505,7 +505,6 @@ function renderRoutes(opts) {
505
505
  }
506
506
 
507
507
  var _excluded$2 = ["history"];
508
-
509
508
  function RouterComponent(props) {
510
509
  var history = props.history,
511
510
  renderRoutesProps = _objectWithoutProperties(props, _excluded$2);
@@ -544,13 +543,32 @@ function RouterComponent(props) {
544
543
  history: history
545
544
  }, renderRoutes(renderRoutesProps));
546
545
  }
546
+
547
+ function getRootContainer(opts) {
548
+ return opts.plugin.applyPlugins({
549
+ type: ApplyPluginsType.modify,
550
+ key: 'rootContainer',
551
+ initialValue: /*#__PURE__*/React.createElement(RouterComponent, {
552
+ history: opts.history,
553
+ routes: opts.routes,
554
+ plugin: opts.plugin,
555
+ ssrProps: opts.ssrProps,
556
+ defaultTitle: opts.defaultTitle
557
+ }),
558
+ args: {
559
+ history: opts.history,
560
+ routes: opts.routes,
561
+ plugin: opts.plugin
562
+ }
563
+ });
564
+ }
565
+
547
566
  /**
548
567
  * preload for SSR in dynamicImport
549
568
  * exec preload Promise function before ReactDOM.hydrate
550
569
  * @param Routes
551
570
  */
552
571
 
553
-
554
572
  function preloadComponent(_x) {
555
573
  return _preloadComponent.apply(this, arguments);
556
574
  }
@@ -647,27 +665,12 @@ function _preloadComponent() {
647
665
  }
648
666
 
649
667
  function renderClient(opts) {
650
- var rootContainer = opts.plugin.applyPlugins({
651
- type: ApplyPluginsType.modify,
652
- key: 'rootContainer',
653
- initialValue: /*#__PURE__*/React.createElement(RouterComponent, {
654
- history: opts.history,
655
- routes: opts.routes,
656
- plugin: opts.plugin,
657
- ssrProps: opts.ssrProps,
658
- defaultTitle: opts.defaultTitle
659
- }),
660
- args: {
661
- history: opts.history,
662
- routes: opts.routes,
663
- plugin: opts.plugin
664
- }
665
- });
668
+ var rootContainer = getRootContainer(opts);
666
669
 
667
670
  if (opts.rootElement) {
668
671
  var rootElement = typeof opts.rootElement === 'string' ? document.getElementById(opts.rootElement) : opts.rootElement;
669
672
 
670
- var callback = opts.callback || function () {}; // flag showing SSR successed
673
+ var callback = opts.callback || function () {}; // flag showing SSR succeed
671
674
 
672
675
 
673
676
  if (window.g_useSSR) {
package/dist/index.js CHANGED
@@ -513,7 +513,6 @@ function renderRoutes(opts) {
513
513
  }
514
514
 
515
515
  var _excluded$2 = ["history"];
516
-
517
516
  function RouterComponent(props) {
518
517
  var history = props.history,
519
518
  renderRoutesProps = _objectWithoutProperties(props, _excluded$2);
@@ -552,13 +551,32 @@ function RouterComponent(props) {
552
551
  history: history
553
552
  }, renderRoutes(renderRoutesProps));
554
553
  }
554
+
555
+ function getRootContainer(opts) {
556
+ return opts.plugin.applyPlugins({
557
+ type: runtime.ApplyPluginsType.modify,
558
+ key: 'rootContainer',
559
+ initialValue: /*#__PURE__*/React__default['default'].createElement(RouterComponent, {
560
+ history: opts.history,
561
+ routes: opts.routes,
562
+ plugin: opts.plugin,
563
+ ssrProps: opts.ssrProps,
564
+ defaultTitle: opts.defaultTitle
565
+ }),
566
+ args: {
567
+ history: opts.history,
568
+ routes: opts.routes,
569
+ plugin: opts.plugin
570
+ }
571
+ });
572
+ }
573
+
555
574
  /**
556
575
  * preload for SSR in dynamicImport
557
576
  * exec preload Promise function before ReactDOM.hydrate
558
577
  * @param Routes
559
578
  */
560
579
 
561
-
562
580
  function preloadComponent(_x) {
563
581
  return _preloadComponent.apply(this, arguments);
564
582
  }
@@ -655,27 +673,12 @@ function _preloadComponent() {
655
673
  }
656
674
 
657
675
  function renderClient(opts) {
658
- var rootContainer = opts.plugin.applyPlugins({
659
- type: runtime.ApplyPluginsType.modify,
660
- key: 'rootContainer',
661
- initialValue: /*#__PURE__*/React__default['default'].createElement(RouterComponent, {
662
- history: opts.history,
663
- routes: opts.routes,
664
- plugin: opts.plugin,
665
- ssrProps: opts.ssrProps,
666
- defaultTitle: opts.defaultTitle
667
- }),
668
- args: {
669
- history: opts.history,
670
- routes: opts.routes,
671
- plugin: opts.plugin
672
- }
673
- });
676
+ var rootContainer = getRootContainer(opts);
674
677
 
675
678
  if (opts.rootElement) {
676
679
  var rootElement = typeof opts.rootElement === 'string' ? document.getElementById(opts.rootElement) : opts.rootElement;
677
680
 
678
- var callback = opts.callback || function () {}; // flag showing SSR successed
681
+ var callback = opts.callback || function () {}; // flag showing SSR succeed
679
682
 
680
683
 
681
684
  if (window.g_useSSR) {
@@ -0,0 +1,2 @@
1
+ export * from './commonExports';
2
+ export { default as renderClient } from './renderClient/renderClient-18';
@@ -0,0 +1,532 @@
1
+ import { __RouterContext, matchPath, Redirect, ApplyPluginsType, Router } from '@umijs/runtime';
2
+ import React, { Children, isValidElement, cloneElement, useState, useEffect, createElement } from 'react';
3
+ import ReactDOM from 'react-dom/client';
4
+ import { matchRoutes } from 'react-router-config';
5
+
6
+ function ownKeys(object, enumerableOnly) {
7
+ var keys = Object.keys(object);
8
+
9
+ if (Object.getOwnPropertySymbols) {
10
+ var symbols = Object.getOwnPropertySymbols(object);
11
+
12
+ if (enumerableOnly) {
13
+ symbols = symbols.filter(function (sym) {
14
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
15
+ });
16
+ }
17
+
18
+ keys.push.apply(keys, symbols);
19
+ }
20
+
21
+ return keys;
22
+ }
23
+
24
+ function _objectSpread2(target) {
25
+ for (var i = 1; i < arguments.length; i++) {
26
+ var source = arguments[i] != null ? arguments[i] : {};
27
+
28
+ if (i % 2) {
29
+ ownKeys(Object(source), true).forEach(function (key) {
30
+ _defineProperty(target, key, source[key]);
31
+ });
32
+ } else if (Object.getOwnPropertyDescriptors) {
33
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
34
+ } else {
35
+ ownKeys(Object(source)).forEach(function (key) {
36
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
37
+ });
38
+ }
39
+ }
40
+
41
+ return target;
42
+ }
43
+
44
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
45
+ try {
46
+ var info = gen[key](arg);
47
+ var value = info.value;
48
+ } catch (error) {
49
+ reject(error);
50
+ return;
51
+ }
52
+
53
+ if (info.done) {
54
+ resolve(value);
55
+ } else {
56
+ Promise.resolve(value).then(_next, _throw);
57
+ }
58
+ }
59
+
60
+ function _asyncToGenerator(fn) {
61
+ return function () {
62
+ var self = this,
63
+ args = arguments;
64
+ return new Promise(function (resolve, reject) {
65
+ var gen = fn.apply(self, args);
66
+
67
+ function _next(value) {
68
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
69
+ }
70
+
71
+ function _throw(err) {
72
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
73
+ }
74
+
75
+ _next(undefined);
76
+ });
77
+ };
78
+ }
79
+
80
+ function _defineProperty(obj, key, value) {
81
+ if (key in obj) {
82
+ Object.defineProperty(obj, key, {
83
+ value: value,
84
+ enumerable: true,
85
+ configurable: true,
86
+ writable: true
87
+ });
88
+ } else {
89
+ obj[key] = value;
90
+ }
91
+
92
+ return obj;
93
+ }
94
+
95
+ function _extends() {
96
+ _extends = Object.assign || function (target) {
97
+ for (var i = 1; i < arguments.length; i++) {
98
+ var source = arguments[i];
99
+
100
+ for (var key in source) {
101
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
102
+ target[key] = source[key];
103
+ }
104
+ }
105
+ }
106
+
107
+ return target;
108
+ };
109
+
110
+ return _extends.apply(this, arguments);
111
+ }
112
+
113
+ function _objectWithoutPropertiesLoose(source, excluded) {
114
+ if (source == null) return {};
115
+ var target = {};
116
+ var sourceKeys = Object.keys(source);
117
+ var key, i;
118
+
119
+ for (i = 0; i < sourceKeys.length; i++) {
120
+ key = sourceKeys[i];
121
+ if (excluded.indexOf(key) >= 0) continue;
122
+ target[key] = source[key];
123
+ }
124
+
125
+ return target;
126
+ }
127
+
128
+ function _objectWithoutProperties(source, excluded) {
129
+ if (source == null) return {};
130
+
131
+ var target = _objectWithoutPropertiesLoose(source, excluded);
132
+
133
+ var key, i;
134
+
135
+ if (Object.getOwnPropertySymbols) {
136
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
137
+
138
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
139
+ key = sourceSymbolKeys[i];
140
+ if (excluded.indexOf(key) >= 0) continue;
141
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
142
+ target[key] = source[key];
143
+ }
144
+ }
145
+
146
+ return target;
147
+ }
148
+
149
+ function _slicedToArray(arr, i) {
150
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
151
+ }
152
+
153
+ function _arrayWithHoles(arr) {
154
+ if (Array.isArray(arr)) return arr;
155
+ }
156
+
157
+ function _iterableToArrayLimit(arr, i) {
158
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
159
+
160
+ if (_i == null) return;
161
+ var _arr = [];
162
+ var _n = true;
163
+ var _d = false;
164
+
165
+ var _s, _e;
166
+
167
+ try {
168
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
169
+ _arr.push(_s.value);
170
+
171
+ if (i && _arr.length === i) break;
172
+ }
173
+ } catch (err) {
174
+ _d = true;
175
+ _e = err;
176
+ } finally {
177
+ try {
178
+ if (!_n && _i["return"] != null) _i["return"]();
179
+ } finally {
180
+ if (_d) throw _e;
181
+ }
182
+ }
183
+
184
+ return _arr;
185
+ }
186
+
187
+ function _unsupportedIterableToArray(o, minLen) {
188
+ if (!o) return;
189
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
190
+ var n = Object.prototype.toString.call(o).slice(8, -1);
191
+ if (n === "Object" && o.constructor) n = o.constructor.name;
192
+ if (n === "Map" || n === "Set") return Array.from(o);
193
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
194
+ }
195
+
196
+ function _arrayLikeToArray(arr, len) {
197
+ if (len == null || len > arr.length) len = arr.length;
198
+
199
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
200
+
201
+ return arr2;
202
+ }
203
+
204
+ function _nonIterableRest() {
205
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
206
+ }
207
+
208
+ function Route(props) {
209
+ return /*#__PURE__*/React.createElement(__RouterContext.Consumer, null, function (context) {
210
+ var location = props.location || context.location;
211
+ var match = props.computedMatch;
212
+
213
+ var newProps = _objectSpread2(_objectSpread2({}, context), {}, {
214
+ location: location,
215
+ match: match
216
+ });
217
+
218
+ var render = props.render;
219
+ return /*#__PURE__*/React.createElement(__RouterContext.Provider, {
220
+ value: newProps
221
+ }, newProps.match ? render(_objectSpread2(_objectSpread2({}, props.layoutProps), newProps)) : null);
222
+ });
223
+ }
224
+
225
+ var _excluded = ["children"];
226
+ function Switch(props) {
227
+ return /*#__PURE__*/React.createElement(__RouterContext.Consumer, null, function (context) {
228
+ var children = props.children,
229
+ extraProps = _objectWithoutProperties(props, _excluded);
230
+
231
+ var location = props.location || context.location;
232
+ var element,
233
+ match = null;
234
+ Children.forEach(children, function (child) {
235
+ if (match === null && /*#__PURE__*/isValidElement(child)) {
236
+ element = child;
237
+ var path = child.props.path || child.props.from;
238
+ match = path ? matchPath(location.pathname, _objectSpread2(_objectSpread2({}, child.props), {}, {
239
+ path: path
240
+ })) : context.match;
241
+ }
242
+ });
243
+ return match ? /*#__PURE__*/cloneElement(element, {
244
+ location: location,
245
+ computedMatch: match,
246
+ layoutProps: extraProps
247
+ }) : null;
248
+ });
249
+ }
250
+
251
+ var _excluded$1 = ["component"];
252
+
253
+ function wrapInitialPropsFetch(route, opts) {
254
+ var component = route.component,
255
+ restRouteParams = _objectWithoutProperties(route, _excluded$1);
256
+
257
+ var Component = route.component;
258
+
259
+ function ComponentWithInitialPropsFetch(props) {
260
+ var _useState = useState(function () {
261
+ return window.g_initialProps;
262
+ }),
263
+ _useState2 = _slicedToArray(_useState, 2),
264
+ initialProps = _useState2[0],
265
+ setInitialProps = _useState2[1];
266
+
267
+ useEffect(function () {
268
+ /**
269
+ * 1. 首次渲染时,此时 window.g_initialProps 变量存在,不需要再走一次 getInitialProps,这样一次 SSR 就走了 2 次 getInitialProps
270
+ * 2. 但是路由切换时,window.getInitialProps 会被赋为 null,这时候就走 getInitialProps 逻辑
271
+ * 3. 如果任何时候都走 2 次,配置 forceInitial: true,这个场景用于静态站点的首屏加载希望走最新数据
272
+ * 4. 开启动态加载后,会在执行 getInitialProps 前预加载下
273
+ */
274
+ var handleGetInitialProps = /*#__PURE__*/function () {
275
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
276
+ var _preloadComponent;
277
+
278
+ var preloadComponent, defaultCtx, ctx, _initialProps;
279
+
280
+ return regeneratorRuntime.wrap(function _callee$(_context) {
281
+ while (1) {
282
+ switch (_context.prev = _context.next) {
283
+ case 0:
284
+ // preload when enalbe dynamicImport
285
+ preloadComponent = Component;
286
+
287
+ if (!Component.preload) {
288
+ _context.next = 6;
289
+ break;
290
+ }
291
+
292
+ _context.next = 4;
293
+ return Component.preload();
294
+
295
+ case 4:
296
+ preloadComponent = _context.sent;
297
+ // for test case, really use .default
298
+ preloadComponent = preloadComponent.default || preloadComponent;
299
+
300
+ case 6:
301
+ defaultCtx = _objectSpread2(_objectSpread2({
302
+ isServer: false,
303
+ match: props === null || props === void 0 ? void 0 : props.match,
304
+ history: props === null || props === void 0 ? void 0 : props.history,
305
+ route: route
306
+ }, opts.getInitialPropsCtx || {}), restRouteParams);
307
+
308
+ if (!((_preloadComponent = preloadComponent) === null || _preloadComponent === void 0 ? void 0 : _preloadComponent.getInitialProps)) {
309
+ _context.next = 15;
310
+ break;
311
+ }
312
+
313
+ _context.next = 10;
314
+ return opts.plugin.applyPlugins({
315
+ key: 'ssr.modifyGetInitialPropsCtx',
316
+ type: ApplyPluginsType.modify,
317
+ initialValue: defaultCtx,
318
+ async: true
319
+ });
320
+
321
+ case 10:
322
+ ctx = _context.sent;
323
+ _context.next = 13;
324
+ return preloadComponent.getInitialProps(ctx || defaultCtx);
325
+
326
+ case 13:
327
+ _initialProps = _context.sent;
328
+ setInitialProps(_initialProps);
329
+
330
+ case 15:
331
+ case "end":
332
+ return _context.stop();
333
+ }
334
+ }
335
+ }, _callee);
336
+ }));
337
+
338
+ return function handleGetInitialProps() {
339
+ return _ref.apply(this, arguments);
340
+ };
341
+ }(); // null 时,一定会触发 getInitialProps 执行
342
+
343
+
344
+ if (!window.g_initialProps) {
345
+ handleGetInitialProps();
346
+ }
347
+ }, [window.location.pathname, window.location.search]);
348
+ return /*#__PURE__*/React.createElement(Component, _extends({}, props, initialProps));
349
+ } // flag for having wrappered
350
+
351
+
352
+ ComponentWithInitialPropsFetch.wrapInitialPropsLoaded = true;
353
+ ComponentWithInitialPropsFetch.displayName = 'ComponentWithInitialPropsFetch';
354
+ return ComponentWithInitialPropsFetch;
355
+ }
356
+
357
+ function _render(_ref2) {
358
+ var route = _ref2.route,
359
+ opts = _ref2.opts,
360
+ props = _ref2.props;
361
+ var routes = renderRoutes(_objectSpread2(_objectSpread2({}, opts), {}, {
362
+ routes: route.routes || [],
363
+ rootRoutes: opts.rootRoutes
364
+ }), {
365
+ location: props.location
366
+ });
367
+ var Component = route.component,
368
+ wrappers = route.wrappers;
369
+
370
+ if (Component) {
371
+ var defaultPageInitialProps = opts.isServer ? {} : window.g_initialProps;
372
+
373
+ var newProps = _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, props), opts.extraProps), opts.pageInitialProps || defaultPageInitialProps), {}, {
374
+ route: route,
375
+ routes: opts.rootRoutes
376
+ }); // @ts-ignore
377
+
378
+
379
+ var ret = /*#__PURE__*/React.createElement(Component, newProps, routes); // route.wrappers
380
+
381
+ if (wrappers) {
382
+ var len = wrappers.length - 1;
383
+
384
+ while (len >= 0) {
385
+ ret = /*#__PURE__*/createElement(wrappers[len], newProps, ret);
386
+ len -= 1;
387
+ }
388
+ }
389
+
390
+ return ret;
391
+ } else {
392
+ return routes;
393
+ }
394
+ }
395
+
396
+ function getRouteElement(_ref3) {
397
+ var route = _ref3.route,
398
+ index = _ref3.index,
399
+ opts = _ref3.opts;
400
+ var routeProps = {
401
+ key: route.key || index,
402
+ exact: route.exact,
403
+ strict: route.strict,
404
+ sensitive: route.sensitive,
405
+ path: route.path
406
+ };
407
+
408
+ if (route.redirect) {
409
+ return /*#__PURE__*/React.createElement(Redirect, _extends({}, routeProps, {
410
+ from: route.path,
411
+ to: route.redirect
412
+ }));
413
+ } else {
414
+ var _route$component, _route$component2, _route$component3;
415
+
416
+ // avoid mount and unmount with url hash change
417
+ if ( // only when SSR config enable
418
+ opts.ssrProps && !opts.isServer && // make sure loaded once
419
+ !((_route$component = route.component) === null || _route$component === void 0 ? void 0 : _route$component.wrapInitialPropsLoaded) && ( // TODO need a type
420
+ ((_route$component2 = route.component) === null || _route$component2 === void 0 ? void 0 : _route$component2.getInitialProps) || ((_route$component3 = route.component) === null || _route$component3 === void 0 ? void 0 : _route$component3.preload))) {
421
+ // client Render for enable ssr, but not sure SSR success
422
+ route.component = wrapInitialPropsFetch(route, opts);
423
+ }
424
+
425
+ return /*#__PURE__*/React.createElement(Route, _extends({}, routeProps, {
426
+ render: function render(props) {
427
+ return _render({
428
+ route: route,
429
+ opts: opts,
430
+ props: props
431
+ });
432
+ }
433
+ }));
434
+ }
435
+ }
436
+
437
+ function renderRoutes(opts) {
438
+ var switchProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
439
+ return opts.routes ? /*#__PURE__*/React.createElement(Switch, switchProps, opts.routes.map(function (route, index) {
440
+ return getRouteElement({
441
+ route: route,
442
+ index: index,
443
+ opts: _objectSpread2(_objectSpread2({}, opts), {}, {
444
+ rootRoutes: opts.rootRoutes || opts.routes
445
+ })
446
+ });
447
+ })) : null;
448
+ }
449
+
450
+ var _excluded$2 = ["history"];
451
+ function RouterComponent(props) {
452
+ var history = props.history,
453
+ renderRoutesProps = _objectWithoutProperties(props, _excluded$2);
454
+
455
+ useEffect(function () {
456
+ // first time using window.g_initialProps
457
+ // switch route fetching data, if exact route reset window.getInitialProps
458
+ if (window.g_useSSR) {
459
+ window.g_initialProps = null;
460
+ }
461
+
462
+ function routeChangeHandler(location, action) {
463
+ var matchedRoutes = matchRoutes(props.routes, location.pathname); // Set title
464
+
465
+ if (typeof document !== 'undefined' && renderRoutesProps.defaultTitle !== undefined) {
466
+ document.title = matchedRoutes.length && // @ts-ignore
467
+ matchedRoutes[matchedRoutes.length - 1].route.title || renderRoutesProps.defaultTitle || '';
468
+ }
469
+
470
+ props.plugin.applyPlugins({
471
+ key: 'onRouteChange',
472
+ type: ApplyPluginsType.event,
473
+ args: {
474
+ routes: props.routes,
475
+ matchedRoutes: matchedRoutes,
476
+ location: location,
477
+ action: action
478
+ }
479
+ });
480
+ }
481
+
482
+ routeChangeHandler(history.location, 'POP');
483
+ return history.listen(routeChangeHandler);
484
+ }, [history]);
485
+ return /*#__PURE__*/React.createElement(Router, {
486
+ history: history
487
+ }, renderRoutes(renderRoutesProps));
488
+ }
489
+
490
+ function getRootContainer(opts) {
491
+ return opts.plugin.applyPlugins({
492
+ type: ApplyPluginsType.modify,
493
+ key: 'rootContainer',
494
+ initialValue: /*#__PURE__*/React.createElement(RouterComponent, {
495
+ history: opts.history,
496
+ routes: opts.routes,
497
+ plugin: opts.plugin,
498
+ ssrProps: opts.ssrProps,
499
+ defaultTitle: opts.defaultTitle
500
+ }),
501
+ args: {
502
+ history: opts.history,
503
+ routes: opts.routes,
504
+ plugin: opts.plugin
505
+ }
506
+ });
507
+ }
508
+
509
+ // @ts-ignore
510
+ function renderClient(opts) {
511
+ var rootContainer = getRootContainer(opts);
512
+
513
+ if (opts.rootElement) {
514
+ var rootElement = typeof opts.rootElement === 'string' ? document.getElementById(opts.rootElement) : opts.rootElement;
515
+
516
+ var callback = opts.callback || function () {}; // flag showing SSR succeed
517
+
518
+
519
+ if (window.g_useSSR) {
520
+ ReactDOM.hydrateRoot(rootElement, rootContainer);
521
+ callback();
522
+ } else {
523
+ var root = ReactDOM.createRoot(rootElement);
524
+ root.render(rootContainer);
525
+ callback();
526
+ }
527
+ } else {
528
+ return rootContainer;
529
+ }
530
+ }
531
+
532
+ export { renderClient, renderRoutes };
@@ -0,0 +1,542 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var runtime = require('@umijs/runtime');
6
+ var React = require('react');
7
+ var ReactDOM = require('react-dom/client');
8
+ var reactRouterConfig = require('react-router-config');
9
+
10
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
+
12
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
13
+ var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
14
+
15
+ function ownKeys(object, enumerableOnly) {
16
+ var keys = Object.keys(object);
17
+
18
+ if (Object.getOwnPropertySymbols) {
19
+ var symbols = Object.getOwnPropertySymbols(object);
20
+
21
+ if (enumerableOnly) {
22
+ symbols = symbols.filter(function (sym) {
23
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
24
+ });
25
+ }
26
+
27
+ keys.push.apply(keys, symbols);
28
+ }
29
+
30
+ return keys;
31
+ }
32
+
33
+ function _objectSpread2(target) {
34
+ for (var i = 1; i < arguments.length; i++) {
35
+ var source = arguments[i] != null ? arguments[i] : {};
36
+
37
+ if (i % 2) {
38
+ ownKeys(Object(source), true).forEach(function (key) {
39
+ _defineProperty(target, key, source[key]);
40
+ });
41
+ } else if (Object.getOwnPropertyDescriptors) {
42
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
43
+ } else {
44
+ ownKeys(Object(source)).forEach(function (key) {
45
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
46
+ });
47
+ }
48
+ }
49
+
50
+ return target;
51
+ }
52
+
53
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
54
+ try {
55
+ var info = gen[key](arg);
56
+ var value = info.value;
57
+ } catch (error) {
58
+ reject(error);
59
+ return;
60
+ }
61
+
62
+ if (info.done) {
63
+ resolve(value);
64
+ } else {
65
+ Promise.resolve(value).then(_next, _throw);
66
+ }
67
+ }
68
+
69
+ function _asyncToGenerator(fn) {
70
+ return function () {
71
+ var self = this,
72
+ args = arguments;
73
+ return new Promise(function (resolve, reject) {
74
+ var gen = fn.apply(self, args);
75
+
76
+ function _next(value) {
77
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
78
+ }
79
+
80
+ function _throw(err) {
81
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
82
+ }
83
+
84
+ _next(undefined);
85
+ });
86
+ };
87
+ }
88
+
89
+ function _defineProperty(obj, key, value) {
90
+ if (key in obj) {
91
+ Object.defineProperty(obj, key, {
92
+ value: value,
93
+ enumerable: true,
94
+ configurable: true,
95
+ writable: true
96
+ });
97
+ } else {
98
+ obj[key] = value;
99
+ }
100
+
101
+ return obj;
102
+ }
103
+
104
+ function _extends() {
105
+ _extends = Object.assign || function (target) {
106
+ for (var i = 1; i < arguments.length; i++) {
107
+ var source = arguments[i];
108
+
109
+ for (var key in source) {
110
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
111
+ target[key] = source[key];
112
+ }
113
+ }
114
+ }
115
+
116
+ return target;
117
+ };
118
+
119
+ return _extends.apply(this, arguments);
120
+ }
121
+
122
+ function _objectWithoutPropertiesLoose(source, excluded) {
123
+ if (source == null) return {};
124
+ var target = {};
125
+ var sourceKeys = Object.keys(source);
126
+ var key, i;
127
+
128
+ for (i = 0; i < sourceKeys.length; i++) {
129
+ key = sourceKeys[i];
130
+ if (excluded.indexOf(key) >= 0) continue;
131
+ target[key] = source[key];
132
+ }
133
+
134
+ return target;
135
+ }
136
+
137
+ function _objectWithoutProperties(source, excluded) {
138
+ if (source == null) return {};
139
+
140
+ var target = _objectWithoutPropertiesLoose(source, excluded);
141
+
142
+ var key, i;
143
+
144
+ if (Object.getOwnPropertySymbols) {
145
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
146
+
147
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
148
+ key = sourceSymbolKeys[i];
149
+ if (excluded.indexOf(key) >= 0) continue;
150
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
151
+ target[key] = source[key];
152
+ }
153
+ }
154
+
155
+ return target;
156
+ }
157
+
158
+ function _slicedToArray(arr, i) {
159
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
160
+ }
161
+
162
+ function _arrayWithHoles(arr) {
163
+ if (Array.isArray(arr)) return arr;
164
+ }
165
+
166
+ function _iterableToArrayLimit(arr, i) {
167
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
168
+
169
+ if (_i == null) return;
170
+ var _arr = [];
171
+ var _n = true;
172
+ var _d = false;
173
+
174
+ var _s, _e;
175
+
176
+ try {
177
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
178
+ _arr.push(_s.value);
179
+
180
+ if (i && _arr.length === i) break;
181
+ }
182
+ } catch (err) {
183
+ _d = true;
184
+ _e = err;
185
+ } finally {
186
+ try {
187
+ if (!_n && _i["return"] != null) _i["return"]();
188
+ } finally {
189
+ if (_d) throw _e;
190
+ }
191
+ }
192
+
193
+ return _arr;
194
+ }
195
+
196
+ function _unsupportedIterableToArray(o, minLen) {
197
+ if (!o) return;
198
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
199
+ var n = Object.prototype.toString.call(o).slice(8, -1);
200
+ if (n === "Object" && o.constructor) n = o.constructor.name;
201
+ if (n === "Map" || n === "Set") return Array.from(o);
202
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
203
+ }
204
+
205
+ function _arrayLikeToArray(arr, len) {
206
+ if (len == null || len > arr.length) len = arr.length;
207
+
208
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
209
+
210
+ return arr2;
211
+ }
212
+
213
+ function _nonIterableRest() {
214
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
215
+ }
216
+
217
+ function Route(props) {
218
+ return /*#__PURE__*/React__default['default'].createElement(runtime.__RouterContext.Consumer, null, function (context) {
219
+ var location = props.location || context.location;
220
+ var match = props.computedMatch;
221
+
222
+ var newProps = _objectSpread2(_objectSpread2({}, context), {}, {
223
+ location: location,
224
+ match: match
225
+ });
226
+
227
+ var render = props.render;
228
+ return /*#__PURE__*/React__default['default'].createElement(runtime.__RouterContext.Provider, {
229
+ value: newProps
230
+ }, newProps.match ? render(_objectSpread2(_objectSpread2({}, props.layoutProps), newProps)) : null);
231
+ });
232
+ }
233
+
234
+ var _excluded = ["children"];
235
+ function Switch(props) {
236
+ return /*#__PURE__*/React__default['default'].createElement(runtime.__RouterContext.Consumer, null, function (context) {
237
+ var children = props.children,
238
+ extraProps = _objectWithoutProperties(props, _excluded);
239
+
240
+ var location = props.location || context.location;
241
+ var element,
242
+ match = null;
243
+ React.Children.forEach(children, function (child) {
244
+ if (match === null && /*#__PURE__*/React.isValidElement(child)) {
245
+ element = child;
246
+ var path = child.props.path || child.props.from;
247
+ match = path ? runtime.matchPath(location.pathname, _objectSpread2(_objectSpread2({}, child.props), {}, {
248
+ path: path
249
+ })) : context.match;
250
+ }
251
+ });
252
+ return match ? /*#__PURE__*/React.cloneElement(element, {
253
+ location: location,
254
+ computedMatch: match,
255
+ layoutProps: extraProps
256
+ }) : null;
257
+ });
258
+ }
259
+
260
+ var _excluded$1 = ["component"];
261
+
262
+ function wrapInitialPropsFetch(route, opts) {
263
+ var component = route.component,
264
+ restRouteParams = _objectWithoutProperties(route, _excluded$1);
265
+
266
+ var Component = route.component;
267
+
268
+ function ComponentWithInitialPropsFetch(props) {
269
+ var _useState = React.useState(function () {
270
+ return window.g_initialProps;
271
+ }),
272
+ _useState2 = _slicedToArray(_useState, 2),
273
+ initialProps = _useState2[0],
274
+ setInitialProps = _useState2[1];
275
+
276
+ React.useEffect(function () {
277
+ /**
278
+ * 1. 首次渲染时,此时 window.g_initialProps 变量存在,不需要再走一次 getInitialProps,这样一次 SSR 就走了 2 次 getInitialProps
279
+ * 2. 但是路由切换时,window.getInitialProps 会被赋为 null,这时候就走 getInitialProps 逻辑
280
+ * 3. 如果任何时候都走 2 次,配置 forceInitial: true,这个场景用于静态站点的首屏加载希望走最新数据
281
+ * 4. 开启动态加载后,会在执行 getInitialProps 前预加载下
282
+ */
283
+ var handleGetInitialProps = /*#__PURE__*/function () {
284
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
285
+ var _preloadComponent;
286
+
287
+ var preloadComponent, defaultCtx, ctx, _initialProps;
288
+
289
+ return regeneratorRuntime.wrap(function _callee$(_context) {
290
+ while (1) {
291
+ switch (_context.prev = _context.next) {
292
+ case 0:
293
+ // preload when enalbe dynamicImport
294
+ preloadComponent = Component;
295
+
296
+ if (!Component.preload) {
297
+ _context.next = 6;
298
+ break;
299
+ }
300
+
301
+ _context.next = 4;
302
+ return Component.preload();
303
+
304
+ case 4:
305
+ preloadComponent = _context.sent;
306
+ // for test case, really use .default
307
+ preloadComponent = preloadComponent.default || preloadComponent;
308
+
309
+ case 6:
310
+ defaultCtx = _objectSpread2(_objectSpread2({
311
+ isServer: false,
312
+ match: props === null || props === void 0 ? void 0 : props.match,
313
+ history: props === null || props === void 0 ? void 0 : props.history,
314
+ route: route
315
+ }, opts.getInitialPropsCtx || {}), restRouteParams);
316
+
317
+ if (!((_preloadComponent = preloadComponent) === null || _preloadComponent === void 0 ? void 0 : _preloadComponent.getInitialProps)) {
318
+ _context.next = 15;
319
+ break;
320
+ }
321
+
322
+ _context.next = 10;
323
+ return opts.plugin.applyPlugins({
324
+ key: 'ssr.modifyGetInitialPropsCtx',
325
+ type: runtime.ApplyPluginsType.modify,
326
+ initialValue: defaultCtx,
327
+ async: true
328
+ });
329
+
330
+ case 10:
331
+ ctx = _context.sent;
332
+ _context.next = 13;
333
+ return preloadComponent.getInitialProps(ctx || defaultCtx);
334
+
335
+ case 13:
336
+ _initialProps = _context.sent;
337
+ setInitialProps(_initialProps);
338
+
339
+ case 15:
340
+ case "end":
341
+ return _context.stop();
342
+ }
343
+ }
344
+ }, _callee);
345
+ }));
346
+
347
+ return function handleGetInitialProps() {
348
+ return _ref.apply(this, arguments);
349
+ };
350
+ }(); // null 时,一定会触发 getInitialProps 执行
351
+
352
+
353
+ if (!window.g_initialProps) {
354
+ handleGetInitialProps();
355
+ }
356
+ }, [window.location.pathname, window.location.search]);
357
+ return /*#__PURE__*/React__default['default'].createElement(Component, _extends({}, props, initialProps));
358
+ } // flag for having wrappered
359
+
360
+
361
+ ComponentWithInitialPropsFetch.wrapInitialPropsLoaded = true;
362
+ ComponentWithInitialPropsFetch.displayName = 'ComponentWithInitialPropsFetch';
363
+ return ComponentWithInitialPropsFetch;
364
+ }
365
+
366
+ function _render(_ref2) {
367
+ var route = _ref2.route,
368
+ opts = _ref2.opts,
369
+ props = _ref2.props;
370
+ var routes = renderRoutes(_objectSpread2(_objectSpread2({}, opts), {}, {
371
+ routes: route.routes || [],
372
+ rootRoutes: opts.rootRoutes
373
+ }), {
374
+ location: props.location
375
+ });
376
+ var Component = route.component,
377
+ wrappers = route.wrappers;
378
+
379
+ if (Component) {
380
+ var defaultPageInitialProps = opts.isServer ? {} : window.g_initialProps;
381
+
382
+ var newProps = _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, props), opts.extraProps), opts.pageInitialProps || defaultPageInitialProps), {}, {
383
+ route: route,
384
+ routes: opts.rootRoutes
385
+ }); // @ts-ignore
386
+
387
+
388
+ var ret = /*#__PURE__*/React__default['default'].createElement(Component, newProps, routes); // route.wrappers
389
+
390
+ if (wrappers) {
391
+ var len = wrappers.length - 1;
392
+
393
+ while (len >= 0) {
394
+ ret = /*#__PURE__*/React.createElement(wrappers[len], newProps, ret);
395
+ len -= 1;
396
+ }
397
+ }
398
+
399
+ return ret;
400
+ } else {
401
+ return routes;
402
+ }
403
+ }
404
+
405
+ function getRouteElement(_ref3) {
406
+ var route = _ref3.route,
407
+ index = _ref3.index,
408
+ opts = _ref3.opts;
409
+ var routeProps = {
410
+ key: route.key || index,
411
+ exact: route.exact,
412
+ strict: route.strict,
413
+ sensitive: route.sensitive,
414
+ path: route.path
415
+ };
416
+
417
+ if (route.redirect) {
418
+ return /*#__PURE__*/React__default['default'].createElement(runtime.Redirect, _extends({}, routeProps, {
419
+ from: route.path,
420
+ to: route.redirect
421
+ }));
422
+ } else {
423
+ var _route$component, _route$component2, _route$component3;
424
+
425
+ // avoid mount and unmount with url hash change
426
+ if ( // only when SSR config enable
427
+ opts.ssrProps && !opts.isServer && // make sure loaded once
428
+ !((_route$component = route.component) === null || _route$component === void 0 ? void 0 : _route$component.wrapInitialPropsLoaded) && ( // TODO need a type
429
+ ((_route$component2 = route.component) === null || _route$component2 === void 0 ? void 0 : _route$component2.getInitialProps) || ((_route$component3 = route.component) === null || _route$component3 === void 0 ? void 0 : _route$component3.preload))) {
430
+ // client Render for enable ssr, but not sure SSR success
431
+ route.component = wrapInitialPropsFetch(route, opts);
432
+ }
433
+
434
+ return /*#__PURE__*/React__default['default'].createElement(Route, _extends({}, routeProps, {
435
+ render: function render(props) {
436
+ return _render({
437
+ route: route,
438
+ opts: opts,
439
+ props: props
440
+ });
441
+ }
442
+ }));
443
+ }
444
+ }
445
+
446
+ function renderRoutes(opts) {
447
+ var switchProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
448
+ return opts.routes ? /*#__PURE__*/React__default['default'].createElement(Switch, switchProps, opts.routes.map(function (route, index) {
449
+ return getRouteElement({
450
+ route: route,
451
+ index: index,
452
+ opts: _objectSpread2(_objectSpread2({}, opts), {}, {
453
+ rootRoutes: opts.rootRoutes || opts.routes
454
+ })
455
+ });
456
+ })) : null;
457
+ }
458
+
459
+ var _excluded$2 = ["history"];
460
+ function RouterComponent(props) {
461
+ var history = props.history,
462
+ renderRoutesProps = _objectWithoutProperties(props, _excluded$2);
463
+
464
+ React.useEffect(function () {
465
+ // first time using window.g_initialProps
466
+ // switch route fetching data, if exact route reset window.getInitialProps
467
+ if (window.g_useSSR) {
468
+ window.g_initialProps = null;
469
+ }
470
+
471
+ function routeChangeHandler(location, action) {
472
+ var matchedRoutes = reactRouterConfig.matchRoutes(props.routes, location.pathname); // Set title
473
+
474
+ if (typeof document !== 'undefined' && renderRoutesProps.defaultTitle !== undefined) {
475
+ document.title = matchedRoutes.length && // @ts-ignore
476
+ matchedRoutes[matchedRoutes.length - 1].route.title || renderRoutesProps.defaultTitle || '';
477
+ }
478
+
479
+ props.plugin.applyPlugins({
480
+ key: 'onRouteChange',
481
+ type: runtime.ApplyPluginsType.event,
482
+ args: {
483
+ routes: props.routes,
484
+ matchedRoutes: matchedRoutes,
485
+ location: location,
486
+ action: action
487
+ }
488
+ });
489
+ }
490
+
491
+ routeChangeHandler(history.location, 'POP');
492
+ return history.listen(routeChangeHandler);
493
+ }, [history]);
494
+ return /*#__PURE__*/React__default['default'].createElement(runtime.Router, {
495
+ history: history
496
+ }, renderRoutes(renderRoutesProps));
497
+ }
498
+
499
+ function getRootContainer(opts) {
500
+ return opts.plugin.applyPlugins({
501
+ type: runtime.ApplyPluginsType.modify,
502
+ key: 'rootContainer',
503
+ initialValue: /*#__PURE__*/React__default['default'].createElement(RouterComponent, {
504
+ history: opts.history,
505
+ routes: opts.routes,
506
+ plugin: opts.plugin,
507
+ ssrProps: opts.ssrProps,
508
+ defaultTitle: opts.defaultTitle
509
+ }),
510
+ args: {
511
+ history: opts.history,
512
+ routes: opts.routes,
513
+ plugin: opts.plugin
514
+ }
515
+ });
516
+ }
517
+
518
+ // @ts-ignore
519
+ function renderClient(opts) {
520
+ var rootContainer = getRootContainer(opts);
521
+
522
+ if (opts.rootElement) {
523
+ var rootElement = typeof opts.rootElement === 'string' ? document.getElementById(opts.rootElement) : opts.rootElement;
524
+
525
+ var callback = opts.callback || function () {}; // flag showing SSR succeed
526
+
527
+
528
+ if (window.g_useSSR) {
529
+ ReactDOM__default['default'].hydrateRoot(rootElement, rootContainer);
530
+ callback();
531
+ } else {
532
+ var root = ReactDOM__default['default'].createRoot(rootElement);
533
+ root.render(rootContainer);
534
+ callback();
535
+ }
536
+ } else {
537
+ return rootContainer;
538
+ }
539
+ }
540
+
541
+ exports.renderClient = renderClient;
542
+ exports.renderRoutes = renderRoutes;
@@ -0,0 +1,2 @@
1
+ import type { IRouterComponentProps } from './types';
2
+ export default function RouterComponent(props: IRouterComponentProps): JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { IOpts } from './types';
2
+ export default function getRootContainer(opts: IOpts): any;
@@ -0,0 +1,2 @@
1
+ import type { IOpts } from './types';
2
+ export default function renderClient(opts: IOpts): any;
@@ -1,18 +1,5 @@
1
- import { Plugin } from '@umijs/runtime';
2
1
  import { IRoute } from '..';
3
- interface IRouterComponentProps {
4
- routes: IRoute[];
5
- plugin: Plugin;
6
- history: any;
7
- ssrProps?: object;
8
- defaultTitle?: string;
9
- dynamicImport?: boolean;
10
- isServer?: boolean;
11
- }
12
- interface IOpts extends IRouterComponentProps {
13
- rootElement?: string | HTMLElement;
14
- callback?: () => void;
15
- }
2
+ import type { IOpts } from './types';
16
3
  /**
17
4
  * preload for SSR in dynamicImport
18
5
  * exec preload Promise function before ReactDOM.hydrate
@@ -20,4 +7,3 @@ interface IOpts extends IRouterComponentProps {
20
7
  */
21
8
  export declare function preloadComponent(readyRoutes: IRoute[], pathname?: string): Promise<IRoute[]>;
22
9
  export default function renderClient(opts: IOpts): any;
23
- export {};
@@ -0,0 +1,15 @@
1
+ import { Plugin } from '@umijs/runtime';
2
+ import { IRoute } from '../commonExports';
3
+ export interface IRouterComponentProps {
4
+ routes: IRoute[];
5
+ plugin: Plugin;
6
+ history: any;
7
+ ssrProps?: object;
8
+ defaultTitle?: string;
9
+ dynamicImport?: boolean;
10
+ isServer?: boolean;
11
+ }
12
+ export interface IOpts extends IRouterComponentProps {
13
+ rootElement?: string | HTMLElement;
14
+ callback?: () => void;
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/renderer-react",
3
- "version": "3.5.22",
3
+ "version": "3.5.25",
4
4
  "description": "@umijs/renderer-react",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "@types/react": "^16.9.43",
29
29
  "@types/react-dom": "^16.9.8",
30
30
  "@types/react-router-config": "^5.0.2",
31
- "@umijs/runtime": "3.5.22",
31
+ "@umijs/runtime": "3.5.25",
32
32
  "react-router-config": "5.1.1"
33
33
  },
34
34
  "peerDependencies": {