@umijs/renderer-react 4.0.15 → 4.0.18
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/browser.d.ts +1 -0
- package/dist/browser.js +2 -1
- package/dist/routes.d.ts +1 -0
- package/dist/routes.js +80 -34
- package/package.json +1 -1
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',
|
package/dist/routes.d.ts
CHANGED
package/dist/routes.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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
|
-
import React from 'react';
|
|
6
|
-
import { generatePath, Navigate, useParams } from 'react-router-dom';
|
|
7
|
-
import { RouteContext } from "./routeContext";
|
|
8
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
import React, { useMemo } from 'react';
|
|
7
|
+
import { generatePath, Navigate, useParams, useLocation, useNavigate, Outlet } from 'react-router-dom';
|
|
8
|
+
import { RouteContext, useRouteData } from "./routeContext";
|
|
9
9
|
export function createClientRoutes(opts) {
|
|
10
10
|
var routesById = opts.routesById,
|
|
11
11
|
parentId = opts.parentId,
|
|
@@ -13,16 +13,23 @@ export function createClientRoutes(opts) {
|
|
|
13
13
|
return Object.keys(routesById).filter(function (id) {
|
|
14
14
|
return routesById[id].parentId === parentId;
|
|
15
15
|
}).map(function (id) {
|
|
16
|
-
var route = createClientRoute({
|
|
16
|
+
var route = createClientRoute(_objectSpread({
|
|
17
17
|
route: routesById[id],
|
|
18
18
|
routeComponent: routeComponents[id],
|
|
19
|
-
loadingComponent: opts.loadingComponent
|
|
20
|
-
|
|
19
|
+
loadingComponent: opts.loadingComponent,
|
|
20
|
+
reactRouter5Compat: opts.reactRouter5Compat
|
|
21
|
+
}, opts.reactRouter5Compat && {
|
|
22
|
+
// TODO: 这个不准,没考虑 patchClientRoutes 的场景
|
|
23
|
+
hasChildren: Object.keys(routesById).filter(function (rid) {
|
|
24
|
+
return routesById[rid].parentId === id;
|
|
25
|
+
}).length > 0
|
|
26
|
+
}));
|
|
21
27
|
var children = createClientRoutes({
|
|
22
28
|
routesById: routesById,
|
|
23
29
|
routeComponents: routeComponents,
|
|
24
30
|
parentId: route.id,
|
|
25
|
-
loadingComponent: opts.loadingComponent
|
|
31
|
+
loadingComponent: opts.loadingComponent,
|
|
32
|
+
reactRouter5Compat: opts.reactRouter5Compat
|
|
26
33
|
});
|
|
27
34
|
|
|
28
35
|
if (children.length > 0) {
|
|
@@ -43,7 +50,7 @@ function NavigateWithParams(props) {
|
|
|
43
50
|
to: generatePath(props.to, params)
|
|
44
51
|
});
|
|
45
52
|
|
|
46
|
-
return /*#__PURE__*/
|
|
53
|
+
return /*#__PURE__*/React.createElement(Navigate, _extends({
|
|
47
54
|
replace: true
|
|
48
55
|
}, propsWithParams));
|
|
49
56
|
}
|
|
@@ -54,40 +61,79 @@ function createClientRoute(opts) {
|
|
|
54
61
|
var redirect = route.redirect,
|
|
55
62
|
props = _objectWithoutProperties(route, _excluded);
|
|
56
63
|
|
|
64
|
+
var Remote = opts.reactRouter5Compat ? RemoteComponentReactRouter5 : RemoteComponent;
|
|
57
65
|
return _objectSpread({
|
|
58
|
-
element: redirect ? /*#__PURE__*/
|
|
66
|
+
element: redirect ? /*#__PURE__*/React.createElement(NavigateWithParams, {
|
|
59
67
|
to: redirect
|
|
60
|
-
}) : /*#__PURE__*/
|
|
68
|
+
}) : /*#__PURE__*/React.createElement(RouteContext.Provider, {
|
|
61
69
|
value: {
|
|
62
70
|
route: opts.route
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
})
|
|
71
|
+
}
|
|
72
|
+
}, /*#__PURE__*/React.createElement(Remote, {
|
|
73
|
+
loader: /*#__PURE__*/React.memo(opts.routeComponent),
|
|
74
|
+
loadingComponent: opts.loadingComponent || DefaultLoading,
|
|
75
|
+
hasChildren: opts.hasChildren
|
|
76
|
+
}))
|
|
69
77
|
}, props);
|
|
70
78
|
}
|
|
71
79
|
|
|
72
80
|
function DefaultLoading() {
|
|
73
|
-
return /*#__PURE__*/
|
|
81
|
+
return /*#__PURE__*/React.createElement("div", null);
|
|
74
82
|
}
|
|
75
83
|
|
|
76
|
-
function
|
|
77
|
-
var
|
|
84
|
+
function RemoteComponentReactRouter5(props) {
|
|
85
|
+
var location = useLocation();
|
|
86
|
+
var navigate = useNavigate();
|
|
87
|
+
var params = useParams();
|
|
78
88
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
var _useRouteData = useRouteData(),
|
|
90
|
+
route = _useRouteData.route;
|
|
91
|
+
|
|
92
|
+
var match = useMemo(function () {
|
|
93
|
+
return {
|
|
94
|
+
params: params,
|
|
95
|
+
isExact: true,
|
|
96
|
+
path: route.path,
|
|
97
|
+
url: location.pathname
|
|
98
|
+
};
|
|
99
|
+
}, [location.pathname, route.path, params]);
|
|
100
|
+
var history = useMemo(function () {
|
|
101
|
+
return {
|
|
102
|
+
back: function back() {
|
|
103
|
+
return navigate(-1);
|
|
104
|
+
},
|
|
105
|
+
goBack: function goBack() {
|
|
106
|
+
return navigate(-1);
|
|
107
|
+
},
|
|
108
|
+
location: location,
|
|
109
|
+
push: function push(url, state) {
|
|
110
|
+
return navigate(url, {
|
|
111
|
+
state: state
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
replace: function replace(url, state) {
|
|
115
|
+
return navigate(url, {
|
|
116
|
+
replace: true,
|
|
117
|
+
state: state
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}, [location, navigate]); // staticContext 没有兼容 好像没看到对应的兼容写法
|
|
122
|
+
|
|
123
|
+
var Component = props.loader;
|
|
124
|
+
return /*#__PURE__*/React.createElement(React.Suspense, {
|
|
125
|
+
fallback: /*#__PURE__*/React.createElement(props.loadingComponent, null)
|
|
126
|
+
}, /*#__PURE__*/React.createElement(Component, {
|
|
127
|
+
location: location,
|
|
128
|
+
match: match,
|
|
129
|
+
history: history,
|
|
130
|
+
params: params
|
|
131
|
+
}, props.hasChildren && /*#__PURE__*/React.createElement(Outlet, null)));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function RemoteComponent(props) {
|
|
135
|
+
var Component = props.loader;
|
|
136
|
+
return /*#__PURE__*/React.createElement(React.Suspense, {
|
|
137
|
+
fallback: /*#__PURE__*/React.createElement(props.loadingComponent, null)
|
|
138
|
+
}, /*#__PURE__*/React.createElement(Component, null));
|
|
93
139
|
}
|
package/package.json
CHANGED