@module-federation/bridge-react 0.0.0-next-20240731105745 → 0.0.0-next-20240801085730
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/CHANGELOG.md +2 -4
- package/__tests__/bridge.spec.tsx +4 -75
- package/__tests__/util.ts +0 -18
- package/dist/index.cjs.js +74 -129
- package/dist/index.d.ts +7 -15
- package/dist/index.es.js +76 -131
- package/package.json +2 -12
- package/src/create.tsx +25 -25
- package/src/provider.tsx +23 -45
- package/src/remote/index.tsx +54 -96
- package/src/router.tsx +0 -2
- package/vite.config.ts +0 -4
- package/dist/router-v5.cjs.js +0 -80
- package/dist/router-v5.d.ts +0 -8
- package/dist/router-v5.es.js +0 -63
- package/dist/router-v6.cjs.js +0 -87
- package/dist/router-v6.d.ts +0 -11
- package/dist/router-v6.es.js +0 -64
- package/src/router-v5.tsx +0 -78
- package/src/router-v6.tsx +0 -76
package/src/remote/index.tsx
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
useContext,
|
|
3
|
-
useEffect,
|
|
4
|
-
useRef,
|
|
5
|
-
useState,
|
|
6
|
-
forwardRef,
|
|
7
|
-
} from 'react';
|
|
1
|
+
import React, { useContext, useEffect, useRef, useState } from 'react';
|
|
8
2
|
import * as ReactRouterDOM from 'react-router-dom';
|
|
9
3
|
import type { ProviderParams } from '@module-federation/bridge-shared';
|
|
10
4
|
import { LoggerInstance, pathJoin } from '../utils';
|
|
11
5
|
import { dispatchPopstateEnv } from '@module-federation/bridge-shared';
|
|
12
6
|
|
|
13
7
|
declare const __APP_VERSION__: string;
|
|
8
|
+
|
|
14
9
|
export interface RenderFnParams extends ProviderParams {
|
|
15
10
|
dom?: any;
|
|
16
11
|
}
|
|
@@ -32,99 +27,66 @@ interface RemoteAppParams {
|
|
|
32
27
|
exportName: string | number | symbol;
|
|
33
28
|
}
|
|
34
29
|
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (dom) {
|
|
65
|
-
domElement = document.querySelector(dom);
|
|
66
|
-
if (!domElement || !(domElement instanceof HTMLElement)) {
|
|
67
|
-
throw new Error(`Invalid dom: ${dom}`);
|
|
68
|
-
}
|
|
69
|
-
rootRef.current = domElement;
|
|
70
|
-
} else {
|
|
71
|
-
domElement = rootRef.current;
|
|
72
|
-
}
|
|
30
|
+
const RemoteApp = ({
|
|
31
|
+
name,
|
|
32
|
+
memoryRoute,
|
|
33
|
+
basename,
|
|
34
|
+
providerInfo,
|
|
35
|
+
...resProps
|
|
36
|
+
}: RemoteAppParams & ProviderParams) => {
|
|
37
|
+
const rootRef = useRef(null);
|
|
38
|
+
const renderDom = useRef(null);
|
|
39
|
+
const providerInfoRef = useRef<any>(null);
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
const renderTimeout = setTimeout(() => {
|
|
43
|
+
const providerReturn = providerInfo();
|
|
44
|
+
providerInfoRef.current = providerReturn;
|
|
45
|
+
const renderProps = {
|
|
46
|
+
name,
|
|
47
|
+
dom: rootRef.current,
|
|
48
|
+
basename,
|
|
49
|
+
memoryRoute,
|
|
50
|
+
...resProps,
|
|
51
|
+
};
|
|
52
|
+
renderDom.current = rootRef.current;
|
|
53
|
+
LoggerInstance.log(
|
|
54
|
+
`createRemoteComponent LazyComponent render >>>`,
|
|
55
|
+
renderProps,
|
|
56
|
+
);
|
|
57
|
+
providerReturn.render(renderProps);
|
|
58
|
+
});
|
|
73
59
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
providerReturn.render(renderProps);
|
|
60
|
+
return () => {
|
|
61
|
+
clearTimeout(renderTimeout);
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
if (providerInfoRef.current?.destroy) {
|
|
64
|
+
LoggerInstance.log(
|
|
65
|
+
`createRemoteComponent LazyComponent destroy >>>`,
|
|
66
|
+
{ name, basename, dom: renderDom.current },
|
|
67
|
+
);
|
|
68
|
+
providerInfoRef.current?.destroy({
|
|
69
|
+
dom: renderDom.current,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
87
72
|
});
|
|
73
|
+
};
|
|
74
|
+
}, []);
|
|
88
75
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (providerInfoRef.current?.destroy) {
|
|
93
|
-
LoggerInstance.log(
|
|
94
|
-
`createRemoteComponent LazyComponent destroy >>>`,
|
|
95
|
-
{ name, basename, dom: renderDom.current },
|
|
96
|
-
);
|
|
97
|
-
providerInfoRef.current?.destroy({
|
|
98
|
-
dom: renderDom.current,
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
}, []);
|
|
104
|
-
|
|
105
|
-
return dom ? null : (
|
|
106
|
-
<div
|
|
107
|
-
className={props?.className}
|
|
108
|
-
style={props?.style}
|
|
109
|
-
ref={rootRef}
|
|
110
|
-
></div>
|
|
111
|
-
);
|
|
112
|
-
};
|
|
76
|
+
//@ts-ignore
|
|
77
|
+
return <div ref={rootRef}></div>;
|
|
78
|
+
};
|
|
113
79
|
|
|
114
|
-
|
|
115
|
-
return <RemoteApp />;
|
|
116
|
-
});
|
|
80
|
+
(RemoteApp as any)['__APP_VERSION__'] = __APP_VERSION__;
|
|
117
81
|
|
|
118
82
|
interface ExtraDataProps {
|
|
119
83
|
basename?: string;
|
|
120
84
|
}
|
|
121
85
|
|
|
122
|
-
export function withRouterData<
|
|
123
|
-
P extends Parameters<typeof RemoteAppWrapper>[0],
|
|
124
|
-
>(
|
|
86
|
+
export function withRouterData<P extends Parameters<typeof RemoteApp>[0]>(
|
|
125
87
|
WrappedComponent: React.ComponentType<P & ExtraDataProps>,
|
|
126
88
|
): React.FC<Omit<P, keyof ExtraDataProps>> {
|
|
127
|
-
|
|
89
|
+
return (props: any) => {
|
|
128
90
|
let enableDispathPopstate = false;
|
|
129
91
|
let routerContextVal: any;
|
|
130
92
|
try {
|
|
@@ -196,12 +158,8 @@ export function withRouterData<
|
|
|
196
158
|
}, [location]);
|
|
197
159
|
}
|
|
198
160
|
|
|
199
|
-
return <WrappedComponent {...(props as P)} basename={basename}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return forwardRef(function (props, ref) {
|
|
203
|
-
return <Component {...props} ref={ref} />;
|
|
204
|
-
}) as any;
|
|
161
|
+
return <WrappedComponent {...(props as P)} basename={basename} />;
|
|
162
|
+
};
|
|
205
163
|
}
|
|
206
164
|
|
|
207
|
-
export default withRouterData(
|
|
165
|
+
export default withRouterData(RemoteApp);
|
package/src/router.tsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
2
|
// The upper alias react-router-dom$ into this file avoids the loop
|
|
3
3
|
import * as ReactRouterDom from 'react-router-dom/';
|
|
4
|
-
|
|
5
4
|
import { RouterContext } from './context';
|
|
6
5
|
import { LoggerInstance } from './utils';
|
|
7
6
|
|
|
@@ -53,7 +52,6 @@ function WraperRouterProvider(
|
|
|
53
52
|
const createBrowserRouter = (ReactRouterDom as any)[
|
|
54
53
|
'create' + 'BrowserRouter'
|
|
55
54
|
];
|
|
56
|
-
|
|
57
55
|
if (!routerContextProps) return <RouterProvider {...props} />;
|
|
58
56
|
|
|
59
57
|
if (routerContextProps.memoryRoute) {
|
package/vite.config.ts
CHANGED
|
@@ -22,8 +22,6 @@ export default defineConfig({
|
|
|
22
22
|
entry: {
|
|
23
23
|
index: path.resolve(__dirname, 'src/index.ts'),
|
|
24
24
|
router: path.resolve(__dirname, 'src/router.tsx'),
|
|
25
|
-
'router-v5': path.resolve(__dirname, 'src/router-v5.tsx'),
|
|
26
|
-
'router-v6': path.resolve(__dirname, 'src/router-v6.tsx'),
|
|
27
25
|
},
|
|
28
26
|
formats: ['cjs', 'es'],
|
|
29
27
|
fileName: (format, entryName) => `${entryName}.${format}.js`,
|
|
@@ -34,8 +32,6 @@ export default defineConfig({
|
|
|
34
32
|
'@remix-run/router',
|
|
35
33
|
'react-router',
|
|
36
34
|
'react-router-dom/',
|
|
37
|
-
'react-router-dom/index.js',
|
|
38
|
-
'react-router-dom/dist/index.js',
|
|
39
35
|
],
|
|
40
36
|
},
|
|
41
37
|
minify: false,
|
package/dist/router-v5.cjs.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const React = require("react");
|
|
4
|
-
const ReactRouterDom = require("react-router-dom/index.js");
|
|
5
|
-
const context = require("./context--mtFt3tp.cjs");
|
|
6
|
-
function _interopNamespaceDefault(e) {
|
|
7
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
|
-
if (e) {
|
|
9
|
-
for (const k in e) {
|
|
10
|
-
if (k !== "default") {
|
|
11
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: () => e[k]
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
n.default = e;
|
|
20
|
-
return Object.freeze(n);
|
|
21
|
-
}
|
|
22
|
-
const ReactRouterDom__namespace = /* @__PURE__ */ _interopNamespaceDefault(ReactRouterDom);
|
|
23
|
-
function WraperRouter(props) {
|
|
24
|
-
const { basename, ...propsRes } = props;
|
|
25
|
-
const routerContextProps = React.useContext(context.RouterContext) || {};
|
|
26
|
-
context.LoggerInstance.log(`WraperRouter info >>>`, {
|
|
27
|
-
...routerContextProps,
|
|
28
|
-
routerContextProps,
|
|
29
|
-
WraperRouterProps: props
|
|
30
|
-
});
|
|
31
|
-
if (!routerContextProps)
|
|
32
|
-
return /* @__PURE__ */ React.createElement(ReactRouterDom__namespace.BrowserRouter, { ...props });
|
|
33
|
-
if (routerContextProps == null ? void 0 : routerContextProps.memoryRoute) {
|
|
34
|
-
return /* @__PURE__ */ React.createElement(
|
|
35
|
-
ReactRouterDom__namespace.MemoryRouter,
|
|
36
|
-
{
|
|
37
|
-
...props,
|
|
38
|
-
initialEntries: [routerContextProps == null ? void 0 : routerContextProps.memoryRoute.entryPath]
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
return /* @__PURE__ */ React.createElement(
|
|
43
|
-
ReactRouterDom__namespace.BrowserRouter,
|
|
44
|
-
{
|
|
45
|
-
...propsRes,
|
|
46
|
-
basename: (routerContextProps == null ? void 0 : routerContextProps.basename) || basename
|
|
47
|
-
}
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
function WraperRouterProvider(props) {
|
|
51
|
-
const { router, ...propsRes } = props;
|
|
52
|
-
const routerContextProps = React.useContext(context.RouterContext) || {};
|
|
53
|
-
const routers = router.routes;
|
|
54
|
-
context.LoggerInstance.log(`WraperRouterProvider info >>>`, {
|
|
55
|
-
...routerContextProps,
|
|
56
|
-
routerContextProps,
|
|
57
|
-
WraperRouterProviderProps: props,
|
|
58
|
-
router
|
|
59
|
-
});
|
|
60
|
-
const RouterProvider = ReactRouterDom__namespace["RouterProvider"];
|
|
61
|
-
const createMemoryRouter = ReactRouterDom__namespace["createMemoryRouter"];
|
|
62
|
-
const createBrowserRouter = ReactRouterDom__namespace["createBrowserRouter"];
|
|
63
|
-
if (!routerContextProps)
|
|
64
|
-
return /* @__PURE__ */ React.createElement(RouterProvider, { ...props });
|
|
65
|
-
if (routerContextProps.memoryRoute) {
|
|
66
|
-
const MemeoryRouterInstance = createMemoryRouter(routers, {
|
|
67
|
-
initialEntries: [routerContextProps == null ? void 0 : routerContextProps.memoryRoute.entryPath]
|
|
68
|
-
});
|
|
69
|
-
return /* @__PURE__ */ React.createElement(RouterProvider, { router: MemeoryRouterInstance });
|
|
70
|
-
} else {
|
|
71
|
-
const BrowserRouterInstance = createBrowserRouter(routers, {
|
|
72
|
-
basename: routerContextProps.basename,
|
|
73
|
-
future: router.future,
|
|
74
|
-
window: router.window
|
|
75
|
-
});
|
|
76
|
-
return /* @__PURE__ */ React.createElement(RouterProvider, { ...propsRes, router: BrowserRouterInstance });
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
exports.BrowserRouter = WraperRouter;
|
|
80
|
-
exports.RouterProvider = WraperRouterProvider;
|
package/dist/router-v5.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { default as default_2 } from 'react';
|
|
2
|
-
import * as ReactRouterDom from 'react-router-dom/index.js';
|
|
3
|
-
|
|
4
|
-
export declare function BrowserRouter(props: Parameters<typeof ReactRouterDom.BrowserRouter>[0] | Parameters<typeof ReactRouterDom.MemoryRouter>[0]): default_2.JSX.Element;
|
|
5
|
-
|
|
6
|
-
export declare function RouterProvider(props: Parameters<typeof ReactRouterDom.RouterProvider>[0]): default_2.JSX.Element;
|
|
7
|
-
|
|
8
|
-
export { }
|
package/dist/router-v5.es.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import React__default, { useContext } from "react";
|
|
2
|
-
import * as ReactRouterDom from "react-router-dom/index.js";
|
|
3
|
-
import { R as RouterContext, L as LoggerInstance } from "./context-Bw2PEwa6.js";
|
|
4
|
-
function WraperRouter(props) {
|
|
5
|
-
const { basename, ...propsRes } = props;
|
|
6
|
-
const routerContextProps = useContext(RouterContext) || {};
|
|
7
|
-
LoggerInstance.log(`WraperRouter info >>>`, {
|
|
8
|
-
...routerContextProps,
|
|
9
|
-
routerContextProps,
|
|
10
|
-
WraperRouterProps: props
|
|
11
|
-
});
|
|
12
|
-
if (!routerContextProps)
|
|
13
|
-
return /* @__PURE__ */ React__default.createElement(ReactRouterDom.BrowserRouter, { ...props });
|
|
14
|
-
if (routerContextProps == null ? void 0 : routerContextProps.memoryRoute) {
|
|
15
|
-
return /* @__PURE__ */ React__default.createElement(
|
|
16
|
-
ReactRouterDom.MemoryRouter,
|
|
17
|
-
{
|
|
18
|
-
...props,
|
|
19
|
-
initialEntries: [routerContextProps == null ? void 0 : routerContextProps.memoryRoute.entryPath]
|
|
20
|
-
}
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
return /* @__PURE__ */ React__default.createElement(
|
|
24
|
-
ReactRouterDom.BrowserRouter,
|
|
25
|
-
{
|
|
26
|
-
...propsRes,
|
|
27
|
-
basename: (routerContextProps == null ? void 0 : routerContextProps.basename) || basename
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
function WraperRouterProvider(props) {
|
|
32
|
-
const { router, ...propsRes } = props;
|
|
33
|
-
const routerContextProps = useContext(RouterContext) || {};
|
|
34
|
-
const routers = router.routes;
|
|
35
|
-
LoggerInstance.log(`WraperRouterProvider info >>>`, {
|
|
36
|
-
...routerContextProps,
|
|
37
|
-
routerContextProps,
|
|
38
|
-
WraperRouterProviderProps: props,
|
|
39
|
-
router
|
|
40
|
-
});
|
|
41
|
-
const RouterProvider = ReactRouterDom["RouterProvider"];
|
|
42
|
-
const createMemoryRouter = ReactRouterDom["createMemoryRouter"];
|
|
43
|
-
const createBrowserRouter = ReactRouterDom["createBrowserRouter"];
|
|
44
|
-
if (!routerContextProps)
|
|
45
|
-
return /* @__PURE__ */ React__default.createElement(RouterProvider, { ...props });
|
|
46
|
-
if (routerContextProps.memoryRoute) {
|
|
47
|
-
const MemeoryRouterInstance = createMemoryRouter(routers, {
|
|
48
|
-
initialEntries: [routerContextProps == null ? void 0 : routerContextProps.memoryRoute.entryPath]
|
|
49
|
-
});
|
|
50
|
-
return /* @__PURE__ */ React__default.createElement(RouterProvider, { router: MemeoryRouterInstance });
|
|
51
|
-
} else {
|
|
52
|
-
const BrowserRouterInstance = createBrowserRouter(routers, {
|
|
53
|
-
basename: routerContextProps.basename,
|
|
54
|
-
future: router.future,
|
|
55
|
-
window: router.window
|
|
56
|
-
});
|
|
57
|
-
return /* @__PURE__ */ React__default.createElement(RouterProvider, { ...propsRes, router: BrowserRouterInstance });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
export {
|
|
61
|
-
WraperRouter as BrowserRouter,
|
|
62
|
-
WraperRouterProvider as RouterProvider
|
|
63
|
-
};
|
package/dist/router-v6.cjs.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const React = require("react");
|
|
4
|
-
const ReactRouterDom = require("react-router-dom/dist/index.js");
|
|
5
|
-
const context = require("./context--mtFt3tp.cjs");
|
|
6
|
-
function _interopNamespaceDefault(e) {
|
|
7
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
|
-
if (e) {
|
|
9
|
-
for (const k in e) {
|
|
10
|
-
if (k !== "default") {
|
|
11
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: () => e[k]
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
n.default = e;
|
|
20
|
-
return Object.freeze(n);
|
|
21
|
-
}
|
|
22
|
-
const ReactRouterDom__namespace = /* @__PURE__ */ _interopNamespaceDefault(ReactRouterDom);
|
|
23
|
-
function WraperRouter(props) {
|
|
24
|
-
const { basename, ...propsRes } = props;
|
|
25
|
-
const routerContextProps = React.useContext(context.RouterContext) || {};
|
|
26
|
-
context.LoggerInstance.log(`WraperRouter info >>>`, {
|
|
27
|
-
...routerContextProps,
|
|
28
|
-
routerContextProps,
|
|
29
|
-
WraperRouterProps: props
|
|
30
|
-
});
|
|
31
|
-
if (!routerContextProps)
|
|
32
|
-
return /* @__PURE__ */ React.createElement(ReactRouterDom__namespace.BrowserRouter, { ...props });
|
|
33
|
-
if (routerContextProps == null ? void 0 : routerContextProps.memoryRoute) {
|
|
34
|
-
return /* @__PURE__ */ React.createElement(
|
|
35
|
-
ReactRouterDom__namespace.MemoryRouter,
|
|
36
|
-
{
|
|
37
|
-
...props,
|
|
38
|
-
initialEntries: [routerContextProps == null ? void 0 : routerContextProps.memoryRoute.entryPath]
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
return /* @__PURE__ */ React.createElement(
|
|
43
|
-
ReactRouterDom__namespace.BrowserRouter,
|
|
44
|
-
{
|
|
45
|
-
...propsRes,
|
|
46
|
-
basename: (routerContextProps == null ? void 0 : routerContextProps.basename) || basename
|
|
47
|
-
}
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
function WraperRouterProvider(props) {
|
|
51
|
-
const { router, ...propsRes } = props;
|
|
52
|
-
const routerContextProps = React.useContext(context.RouterContext) || {};
|
|
53
|
-
const routers = router.routes;
|
|
54
|
-
context.LoggerInstance.log(`WraperRouterProvider info >>>`, {
|
|
55
|
-
...routerContextProps,
|
|
56
|
-
routerContextProps,
|
|
57
|
-
WraperRouterProviderProps: props,
|
|
58
|
-
router
|
|
59
|
-
});
|
|
60
|
-
const RouterProvider = ReactRouterDom__namespace["RouterProvider"];
|
|
61
|
-
const createMemoryRouter = ReactRouterDom__namespace["createMemoryRouter"];
|
|
62
|
-
const createBrowserRouter = ReactRouterDom__namespace["createBrowserRouter"];
|
|
63
|
-
if (!routerContextProps)
|
|
64
|
-
return /* @__PURE__ */ React.createElement(RouterProvider, { ...props });
|
|
65
|
-
if (routerContextProps.memoryRoute) {
|
|
66
|
-
const MemeoryRouterInstance = createMemoryRouter(routers, {
|
|
67
|
-
initialEntries: [routerContextProps == null ? void 0 : routerContextProps.memoryRoute.entryPath]
|
|
68
|
-
});
|
|
69
|
-
return /* @__PURE__ */ React.createElement(RouterProvider, { router: MemeoryRouterInstance });
|
|
70
|
-
} else {
|
|
71
|
-
const BrowserRouterInstance = createBrowserRouter(routers, {
|
|
72
|
-
basename: routerContextProps.basename,
|
|
73
|
-
future: router.future,
|
|
74
|
-
window: router.window
|
|
75
|
-
});
|
|
76
|
-
return /* @__PURE__ */ React.createElement(RouterProvider, { ...propsRes, router: BrowserRouterInstance });
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
exports.BrowserRouter = WraperRouter;
|
|
80
|
-
exports.RouterProvider = WraperRouterProvider;
|
|
81
|
-
Object.keys(ReactRouterDom).forEach((k) => {
|
|
82
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k))
|
|
83
|
-
Object.defineProperty(exports, k, {
|
|
84
|
-
enumerable: true,
|
|
85
|
-
get: () => ReactRouterDom[k]
|
|
86
|
-
});
|
|
87
|
-
});
|
package/dist/router-v6.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { default as default_2 } from 'react';
|
|
2
|
-
import * as ReactRouterDom from 'react-router-dom/dist/index.js';
|
|
3
|
-
|
|
4
|
-
export declare function BrowserRouter(props: Parameters<typeof ReactRouterDom.BrowserRouter>[0] | Parameters<typeof ReactRouterDom.MemoryRouter>[0]): default_2.JSX.Element;
|
|
5
|
-
|
|
6
|
-
export declare function RouterProvider(props: Parameters<typeof ReactRouterDom.RouterProvider>[0]): default_2.JSX.Element;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export * from "react-router-dom/dist/index.js";
|
|
10
|
-
|
|
11
|
-
export { }
|
package/dist/router-v6.es.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import React__default, { useContext } from "react";
|
|
2
|
-
import * as ReactRouterDom from "react-router-dom/dist/index.js";
|
|
3
|
-
export * from "react-router-dom/dist/index.js";
|
|
4
|
-
import { R as RouterContext, L as LoggerInstance } from "./context-Bw2PEwa6.js";
|
|
5
|
-
function WraperRouter(props) {
|
|
6
|
-
const { basename, ...propsRes } = props;
|
|
7
|
-
const routerContextProps = useContext(RouterContext) || {};
|
|
8
|
-
LoggerInstance.log(`WraperRouter info >>>`, {
|
|
9
|
-
...routerContextProps,
|
|
10
|
-
routerContextProps,
|
|
11
|
-
WraperRouterProps: props
|
|
12
|
-
});
|
|
13
|
-
if (!routerContextProps)
|
|
14
|
-
return /* @__PURE__ */ React__default.createElement(ReactRouterDom.BrowserRouter, { ...props });
|
|
15
|
-
if (routerContextProps == null ? void 0 : routerContextProps.memoryRoute) {
|
|
16
|
-
return /* @__PURE__ */ React__default.createElement(
|
|
17
|
-
ReactRouterDom.MemoryRouter,
|
|
18
|
-
{
|
|
19
|
-
...props,
|
|
20
|
-
initialEntries: [routerContextProps == null ? void 0 : routerContextProps.memoryRoute.entryPath]
|
|
21
|
-
}
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
return /* @__PURE__ */ React__default.createElement(
|
|
25
|
-
ReactRouterDom.BrowserRouter,
|
|
26
|
-
{
|
|
27
|
-
...propsRes,
|
|
28
|
-
basename: (routerContextProps == null ? void 0 : routerContextProps.basename) || basename
|
|
29
|
-
}
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
function WraperRouterProvider(props) {
|
|
33
|
-
const { router, ...propsRes } = props;
|
|
34
|
-
const routerContextProps = useContext(RouterContext) || {};
|
|
35
|
-
const routers = router.routes;
|
|
36
|
-
LoggerInstance.log(`WraperRouterProvider info >>>`, {
|
|
37
|
-
...routerContextProps,
|
|
38
|
-
routerContextProps,
|
|
39
|
-
WraperRouterProviderProps: props,
|
|
40
|
-
router
|
|
41
|
-
});
|
|
42
|
-
const RouterProvider = ReactRouterDom["RouterProvider"];
|
|
43
|
-
const createMemoryRouter = ReactRouterDom["createMemoryRouter"];
|
|
44
|
-
const createBrowserRouter = ReactRouterDom["createBrowserRouter"];
|
|
45
|
-
if (!routerContextProps)
|
|
46
|
-
return /* @__PURE__ */ React__default.createElement(RouterProvider, { ...props });
|
|
47
|
-
if (routerContextProps.memoryRoute) {
|
|
48
|
-
const MemeoryRouterInstance = createMemoryRouter(routers, {
|
|
49
|
-
initialEntries: [routerContextProps == null ? void 0 : routerContextProps.memoryRoute.entryPath]
|
|
50
|
-
});
|
|
51
|
-
return /* @__PURE__ */ React__default.createElement(RouterProvider, { router: MemeoryRouterInstance });
|
|
52
|
-
} else {
|
|
53
|
-
const BrowserRouterInstance = createBrowserRouter(routers, {
|
|
54
|
-
basename: routerContextProps.basename,
|
|
55
|
-
future: router.future,
|
|
56
|
-
window: router.window
|
|
57
|
-
});
|
|
58
|
-
return /* @__PURE__ */ React__default.createElement(RouterProvider, { ...propsRes, router: BrowserRouterInstance });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
export {
|
|
62
|
-
WraperRouter as BrowserRouter,
|
|
63
|
-
WraperRouterProvider as RouterProvider
|
|
64
|
-
};
|
package/src/router-v5.tsx
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
// The upper alias react-router-dom$ into this file avoids the loop
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import * as ReactRouterDom from 'react-router-dom/index.js';
|
|
5
|
-
|
|
6
|
-
import { RouterContext } from './context';
|
|
7
|
-
import { LoggerInstance } from './utils';
|
|
8
|
-
|
|
9
|
-
function WraperRouter(
|
|
10
|
-
props:
|
|
11
|
-
| Parameters<typeof ReactRouterDom.BrowserRouter>[0]
|
|
12
|
-
| Parameters<typeof ReactRouterDom.MemoryRouter>[0],
|
|
13
|
-
) {
|
|
14
|
-
const { basename, ...propsRes } = props;
|
|
15
|
-
const routerContextProps = useContext(RouterContext) || {};
|
|
16
|
-
|
|
17
|
-
LoggerInstance.log(`WraperRouter info >>>`, {
|
|
18
|
-
...routerContextProps,
|
|
19
|
-
routerContextProps,
|
|
20
|
-
WraperRouterProps: props,
|
|
21
|
-
});
|
|
22
|
-
if (!routerContextProps) return <ReactRouterDom.BrowserRouter {...props} />;
|
|
23
|
-
|
|
24
|
-
if (routerContextProps?.memoryRoute) {
|
|
25
|
-
return (
|
|
26
|
-
<ReactRouterDom.MemoryRouter
|
|
27
|
-
{...props}
|
|
28
|
-
initialEntries={[routerContextProps?.memoryRoute.entryPath]}
|
|
29
|
-
/>
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
return (
|
|
33
|
-
<ReactRouterDom.BrowserRouter
|
|
34
|
-
{...propsRes}
|
|
35
|
-
basename={routerContextProps?.basename || basename}
|
|
36
|
-
/>
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function WraperRouterProvider(
|
|
41
|
-
props: Parameters<typeof ReactRouterDom.RouterProvider>[0],
|
|
42
|
-
) {
|
|
43
|
-
const { router, ...propsRes } = props;
|
|
44
|
-
const routerContextProps = useContext(RouterContext) || {};
|
|
45
|
-
const routers = router.routes;
|
|
46
|
-
LoggerInstance.log(`WraperRouterProvider info >>>`, {
|
|
47
|
-
...routerContextProps,
|
|
48
|
-
routerContextProps,
|
|
49
|
-
WraperRouterProviderProps: props,
|
|
50
|
-
router,
|
|
51
|
-
});
|
|
52
|
-
const RouterProvider = (ReactRouterDom as any)['Router' + 'Provider'];
|
|
53
|
-
const createMemoryRouter = (ReactRouterDom as any)['create' + 'MemoryRouter'];
|
|
54
|
-
const createBrowserRouter = (ReactRouterDom as any)[
|
|
55
|
-
'create' + 'BrowserRouter'
|
|
56
|
-
];
|
|
57
|
-
if (!routerContextProps) return <RouterProvider {...props} />;
|
|
58
|
-
|
|
59
|
-
if (routerContextProps.memoryRoute) {
|
|
60
|
-
const MemeoryRouterInstance = createMemoryRouter(routers, {
|
|
61
|
-
initialEntries: [routerContextProps?.memoryRoute.entryPath],
|
|
62
|
-
});
|
|
63
|
-
return <RouterProvider router={MemeoryRouterInstance} />;
|
|
64
|
-
} else {
|
|
65
|
-
const BrowserRouterInstance = createBrowserRouter(routers, {
|
|
66
|
-
basename: routerContextProps.basename,
|
|
67
|
-
future: router.future,
|
|
68
|
-
window: router.window,
|
|
69
|
-
});
|
|
70
|
-
return <RouterProvider {...propsRes} router={BrowserRouterInstance} />;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// @ts-ignore
|
|
75
|
-
// export * from 'react-router-dom/index.js';
|
|
76
|
-
|
|
77
|
-
export { WraperRouter as BrowserRouter };
|
|
78
|
-
export { WraperRouterProvider as RouterProvider };
|