@umijs/renderer-react 4.0.17 → 4.0.20
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/appContext.d.ts +1 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +4 -2
- package/dist/routes.d.ts +1 -0
- package/dist/routes.js +59 -33
- package/package.json +1 -1
package/dist/appContext.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ interface IAppContextType {
|
|
|
10
10
|
clientLoaderData: ILoaderData;
|
|
11
11
|
preloadRoute?: (to: string) => void;
|
|
12
12
|
serverLoaderData: ILoaderData;
|
|
13
|
+
history?: any;
|
|
13
14
|
}
|
|
14
15
|
export declare const AppContext: React.Context<IAppContextType>;
|
|
15
16
|
export declare function useAppData(): IAppContextType;
|
package/dist/browser.d.ts
CHANGED
package/dist/browser.js
CHANGED
|
@@ -66,7 +66,8 @@ export function renderClient(opts) {
|
|
|
66
66
|
var clientRoutes = createClientRoutes({
|
|
67
67
|
routesById: opts.routes,
|
|
68
68
|
routeComponents: opts.routeComponents,
|
|
69
|
-
loadingComponent: opts.loadingComponent
|
|
69
|
+
loadingComponent: opts.loadingComponent,
|
|
70
|
+
reactRouter5Compat: opts.reactRouter5Compat
|
|
70
71
|
});
|
|
71
72
|
opts.pluginManager.applyPlugins({
|
|
72
73
|
key: 'patchClientRoutes',
|
|
@@ -202,7 +203,8 @@ export function renderClient(opts) {
|
|
|
202
203
|
basename: basename,
|
|
203
204
|
clientLoaderData: clientLoaderData,
|
|
204
205
|
serverLoaderData: serverLoaderData,
|
|
205
|
-
preloadRoute: handleRouteChange
|
|
206
|
+
preloadRoute: handleRouteChange,
|
|
207
|
+
history: opts.history
|
|
206
208
|
}
|
|
207
209
|
}, rootContainer);
|
|
208
210
|
};
|
package/dist/routes.d.ts
CHANGED
package/dist/routes.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
3
|
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
3
4
|
var _excluded = ["redirect"];
|
|
4
5
|
// @ts-ignore
|
|
5
6
|
import React from 'react';
|
|
6
|
-
import { generatePath, Navigate, useParams } from 'react-router-dom';
|
|
7
|
-
import { RouteContext } from "./routeContext";
|
|
8
|
-
import {
|
|
7
|
+
import { generatePath, Navigate, useParams, Outlet } from 'react-router-dom';
|
|
8
|
+
import { RouteContext, useRouteData } from "./routeContext";
|
|
9
|
+
import { useAppData } from "./appContext";
|
|
9
10
|
export function createClientRoutes(opts) {
|
|
10
11
|
var routesById = opts.routesById,
|
|
11
12
|
parentId = opts.parentId,
|
|
@@ -13,16 +14,23 @@ export function createClientRoutes(opts) {
|
|
|
13
14
|
return Object.keys(routesById).filter(function (id) {
|
|
14
15
|
return routesById[id].parentId === parentId;
|
|
15
16
|
}).map(function (id) {
|
|
16
|
-
var route = createClientRoute({
|
|
17
|
+
var route = createClientRoute(_objectSpread({
|
|
17
18
|
route: routesById[id],
|
|
18
19
|
routeComponent: routeComponents[id],
|
|
19
|
-
loadingComponent: opts.loadingComponent
|
|
20
|
-
|
|
20
|
+
loadingComponent: opts.loadingComponent,
|
|
21
|
+
reactRouter5Compat: opts.reactRouter5Compat
|
|
22
|
+
}, opts.reactRouter5Compat && {
|
|
23
|
+
// TODO: 这个不准,没考虑 patchClientRoutes 的场景
|
|
24
|
+
hasChildren: Object.keys(routesById).filter(function (rid) {
|
|
25
|
+
return routesById[rid].parentId === id;
|
|
26
|
+
}).length > 0
|
|
27
|
+
}));
|
|
21
28
|
var children = createClientRoutes({
|
|
22
29
|
routesById: routesById,
|
|
23
30
|
routeComponents: routeComponents,
|
|
24
31
|
parentId: route.id,
|
|
25
|
-
loadingComponent: opts.loadingComponent
|
|
32
|
+
loadingComponent: opts.loadingComponent,
|
|
33
|
+
reactRouter5Compat: opts.reactRouter5Compat
|
|
26
34
|
});
|
|
27
35
|
|
|
28
36
|
if (children.length > 0) {
|
|
@@ -43,7 +51,7 @@ function NavigateWithParams(props) {
|
|
|
43
51
|
to: generatePath(props.to, params)
|
|
44
52
|
});
|
|
45
53
|
|
|
46
|
-
return /*#__PURE__*/
|
|
54
|
+
return /*#__PURE__*/React.createElement(Navigate, _extends({
|
|
47
55
|
replace: true
|
|
48
56
|
}, propsWithParams));
|
|
49
57
|
}
|
|
@@ -54,40 +62,58 @@ function createClientRoute(opts) {
|
|
|
54
62
|
var redirect = route.redirect,
|
|
55
63
|
props = _objectWithoutProperties(route, _excluded);
|
|
56
64
|
|
|
65
|
+
var Remote = opts.reactRouter5Compat ? RemoteComponentReactRouter5 : RemoteComponent;
|
|
57
66
|
return _objectSpread({
|
|
58
|
-
element: redirect ? /*#__PURE__*/
|
|
67
|
+
element: redirect ? /*#__PURE__*/React.createElement(NavigateWithParams, {
|
|
59
68
|
to: redirect
|
|
60
|
-
}) : /*#__PURE__*/
|
|
69
|
+
}) : /*#__PURE__*/React.createElement(RouteContext.Provider, {
|
|
61
70
|
value: {
|
|
62
71
|
route: opts.route
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
})
|
|
72
|
+
}
|
|
73
|
+
}, /*#__PURE__*/React.createElement(Remote, {
|
|
74
|
+
loader: /*#__PURE__*/React.memo(opts.routeComponent),
|
|
75
|
+
loadingComponent: opts.loadingComponent || DefaultLoading,
|
|
76
|
+
hasChildren: opts.hasChildren
|
|
77
|
+
}))
|
|
69
78
|
}, props);
|
|
70
79
|
}
|
|
71
80
|
|
|
72
81
|
function DefaultLoading() {
|
|
73
|
-
return /*#__PURE__*/
|
|
82
|
+
return /*#__PURE__*/React.createElement("div", null);
|
|
74
83
|
}
|
|
75
84
|
|
|
76
|
-
function
|
|
77
|
-
var
|
|
85
|
+
function RemoteComponentReactRouter5(props) {
|
|
86
|
+
var _useRouteData = useRouteData(),
|
|
87
|
+
route = _useRouteData.route;
|
|
78
88
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
var _useAppData = useAppData(),
|
|
90
|
+
history = _useAppData.history,
|
|
91
|
+
clientRoutes = _useAppData.clientRoutes;
|
|
92
|
+
|
|
93
|
+
var params = useParams();
|
|
94
|
+
var match = {
|
|
95
|
+
params: params,
|
|
96
|
+
isExact: true,
|
|
97
|
+
path: route.path,
|
|
98
|
+
url: history.location.pathname
|
|
99
|
+
}; // staticContext 没有兼容 好像没看到对应的兼容写法
|
|
100
|
+
|
|
101
|
+
var Component = props.loader;
|
|
102
|
+
return /*#__PURE__*/React.createElement(React.Suspense, {
|
|
103
|
+
fallback: /*#__PURE__*/React.createElement(props.loadingComponent, null)
|
|
104
|
+
}, /*#__PURE__*/React.createElement(Component, {
|
|
105
|
+
location: history.location,
|
|
106
|
+
match: match,
|
|
107
|
+
history: history,
|
|
108
|
+
params: params,
|
|
109
|
+
route: route,
|
|
110
|
+
routes: clientRoutes
|
|
111
|
+
}, props.hasChildren && /*#__PURE__*/React.createElement(Outlet, null)));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function RemoteComponent(props) {
|
|
115
|
+
var Component = props.loader;
|
|
116
|
+
return /*#__PURE__*/React.createElement(React.Suspense, {
|
|
117
|
+
fallback: /*#__PURE__*/React.createElement(props.loadingComponent, null)
|
|
118
|
+
}, /*#__PURE__*/React.createElement(Component, null));
|
|
93
119
|
}
|
package/package.json
CHANGED