@umijs/renderer-react 4.0.0-rc.1 → 4.0.0-rc.10
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 +2 -0
- package/dist/browser.js +17 -12
- package/dist/routes.d.ts +3 -1
- package/dist/routes.js +5 -3
- package/package.json +3 -3
package/dist/browser.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { History } from 'history';
|
|
2
|
+
import React from 'react';
|
|
2
3
|
import { IRouteComponents, IRoutesById } from './types';
|
|
3
4
|
export declare function renderClient(opts: {
|
|
4
5
|
rootElement?: HTMLElement;
|
|
@@ -6,5 +7,6 @@ export declare function renderClient(opts: {
|
|
|
6
7
|
routeComponents: IRouteComponents;
|
|
7
8
|
pluginManager: any;
|
|
8
9
|
basename?: string;
|
|
10
|
+
loadingComponent?: React.ReactNode;
|
|
9
11
|
history: History;
|
|
10
12
|
}): void;
|
package/dist/browser.js
CHANGED
|
@@ -10,18 +10,22 @@ function BrowserRoutes(props) {
|
|
|
10
10
|
location: history.location,
|
|
11
11
|
});
|
|
12
12
|
React.useLayoutEffect(() => history.listen(setState), [history]);
|
|
13
|
-
React.useLayoutEffect(() =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
React.useLayoutEffect(() => {
|
|
14
|
+
function onRouteChange(opts) {
|
|
15
|
+
props.pluginManager.applyPlugins({
|
|
16
|
+
key: 'onRouteChange',
|
|
17
|
+
type: 'event',
|
|
18
|
+
args: {
|
|
19
|
+
routes: props.routes,
|
|
20
|
+
clientRoutes: props.clientRoutes,
|
|
21
|
+
location: opts.location,
|
|
22
|
+
action: opts.action,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
history.listen(onRouteChange);
|
|
27
|
+
onRouteChange({ location: state.location, action: state.action });
|
|
28
|
+
}, [history, props.routes, props.clientRoutes]);
|
|
25
29
|
return (React.createElement(Router, { navigator: history, location: state.location, basename: props.basename }, props.children));
|
|
26
30
|
}
|
|
27
31
|
function Routes() {
|
|
@@ -34,6 +38,7 @@ export function renderClient(opts) {
|
|
|
34
38
|
const clientRoutes = createClientRoutes({
|
|
35
39
|
routesById: opts.routes,
|
|
36
40
|
routeComponents: opts.routeComponents,
|
|
41
|
+
loadingComponent: opts.loadingComponent,
|
|
37
42
|
});
|
|
38
43
|
let rootContainer = (React.createElement(BrowserRoutes, { basename: basename, pluginManager: opts.pluginManager, routes: opts.routes, clientRoutes: clientRoutes, history: opts.history },
|
|
39
44
|
React.createElement(Routes, null)));
|
package/dist/routes.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { IRoute, IRoutesById } from './types';
|
|
3
3
|
export declare function createClientRoutes(opts: {
|
|
4
4
|
routesById: IRoutesById;
|
|
5
5
|
routeComponents: Record<string, any>;
|
|
6
6
|
parentId?: string;
|
|
7
|
+
loadingComponent?: React.ReactNode;
|
|
7
8
|
}): {
|
|
8
9
|
parentId?: string | undefined;
|
|
9
10
|
id: string;
|
|
@@ -14,6 +15,7 @@ export declare function createClientRoutes(opts: {
|
|
|
14
15
|
export declare function createClientRoute(opts: {
|
|
15
16
|
route: IRoute;
|
|
16
17
|
routeComponent: any;
|
|
18
|
+
loadingComponent?: React.ReactNode;
|
|
17
19
|
}): {
|
|
18
20
|
parentId?: string | undefined;
|
|
19
21
|
id: string;
|
package/dist/routes.js
CHANGED
|
@@ -22,11 +22,13 @@ export function createClientRoutes(opts) {
|
|
|
22
22
|
const route = createClientRoute({
|
|
23
23
|
route: routesById[id],
|
|
24
24
|
routeComponent: routeComponents[id],
|
|
25
|
+
loadingComponent: opts.loadingComponent,
|
|
25
26
|
});
|
|
26
27
|
const children = createClientRoutes({
|
|
27
28
|
routesById,
|
|
28
29
|
routeComponents,
|
|
29
30
|
parentId: route.id,
|
|
31
|
+
loadingComponent: opts.loadingComponent,
|
|
30
32
|
});
|
|
31
33
|
if (children.length > 0) {
|
|
32
34
|
// @ts-ignore
|
|
@@ -45,14 +47,14 @@ export function createClientRoute(opts) {
|
|
|
45
47
|
return Object.assign({ id: id, path: path, index: index, element: redirect ? (React.createElement(Navigate, { to: redirect })) : (React.createElement(RouteContext.Provider, { value: {
|
|
46
48
|
route: opts.route,
|
|
47
49
|
} },
|
|
48
|
-
React.createElement(RemoteComponent, { loader: opts.routeComponent }))) }, props);
|
|
50
|
+
React.createElement(RemoteComponent, { loader: opts.routeComponent, loadingComponent: opts.loadingComponent || DefaultLoading }))) }, props);
|
|
49
51
|
}
|
|
50
52
|
function DefaultLoading() {
|
|
51
|
-
return React.createElement("div", null
|
|
53
|
+
return React.createElement("div", null);
|
|
52
54
|
}
|
|
53
55
|
function RemoteComponent(props) {
|
|
54
56
|
const Component = loadable(props.loader, {
|
|
55
|
-
fallback: React.createElement(
|
|
57
|
+
fallback: React.createElement(props.loadingComponent, null),
|
|
56
58
|
});
|
|
57
59
|
return React.createElement(Component, null);
|
|
58
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/renderer-react",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.10",
|
|
4
4
|
"description": "@umijs/renderer-react",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/renderer-react#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@loadable/component": "5.15.2",
|
|
25
|
-
"history": "5.
|
|
26
|
-
"react-router-dom": "6.
|
|
25
|
+
"history": "5.3.0",
|
|
26
|
+
"react-router-dom": "6.2.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"react": "17.0.2",
|