@module-federation/bridge-react 0.0.0-next-20240726075341 → 0.0.0-next-20240726084328
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 -2
- package/dist/index.cjs.js +111 -74
- package/dist/index.d.ts +15 -7
- package/dist/index.es.js +113 -76
- package/dist/router-v5.cjs.js +80 -0
- package/dist/router-v5.d.ts +8 -0
- package/dist/router-v5.es.js +63 -0
- package/dist/router-v6.cjs.js +87 -0
- package/dist/router-v6.d.ts +11 -0
- package/dist/router-v6.es.js +64 -0
- package/package.json +12 -2
- package/src/create.tsx +19 -24
- package/src/provider.tsx +37 -23
- package/src/remote/index.tsx +78 -55
- package/src/router-v5.tsx +78 -0
- package/src/router-v6.tsx +76 -0
- package/src/router.tsx +2 -0
- package/vite.config.ts +4 -0
|
@@ -0,0 +1,78 @@
|
|
|
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 };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
// The upper alias react-router-dom$ into this file avoids the loop
|
|
3
|
+
import * as ReactRouterDom from 'react-router-dom/dist/index.js';
|
|
4
|
+
|
|
5
|
+
import { RouterContext } from './context';
|
|
6
|
+
import { LoggerInstance } from './utils';
|
|
7
|
+
|
|
8
|
+
function WraperRouter(
|
|
9
|
+
props:
|
|
10
|
+
| Parameters<typeof ReactRouterDom.BrowserRouter>[0]
|
|
11
|
+
| Parameters<typeof ReactRouterDom.MemoryRouter>[0],
|
|
12
|
+
) {
|
|
13
|
+
const { basename, ...propsRes } = props;
|
|
14
|
+
const routerContextProps = useContext(RouterContext) || {};
|
|
15
|
+
|
|
16
|
+
LoggerInstance.log(`WraperRouter info >>>`, {
|
|
17
|
+
...routerContextProps,
|
|
18
|
+
routerContextProps,
|
|
19
|
+
WraperRouterProps: props,
|
|
20
|
+
});
|
|
21
|
+
if (!routerContextProps) return <ReactRouterDom.BrowserRouter {...props} />;
|
|
22
|
+
|
|
23
|
+
if (routerContextProps?.memoryRoute) {
|
|
24
|
+
return (
|
|
25
|
+
<ReactRouterDom.MemoryRouter
|
|
26
|
+
{...props}
|
|
27
|
+
initialEntries={[routerContextProps?.memoryRoute.entryPath]}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return (
|
|
32
|
+
<ReactRouterDom.BrowserRouter
|
|
33
|
+
{...propsRes}
|
|
34
|
+
basename={routerContextProps?.basename || basename}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function WraperRouterProvider(
|
|
40
|
+
props: Parameters<typeof ReactRouterDom.RouterProvider>[0],
|
|
41
|
+
) {
|
|
42
|
+
const { router, ...propsRes } = props;
|
|
43
|
+
const routerContextProps = useContext(RouterContext) || {};
|
|
44
|
+
const routers = router.routes;
|
|
45
|
+
LoggerInstance.log(`WraperRouterProvider info >>>`, {
|
|
46
|
+
...routerContextProps,
|
|
47
|
+
routerContextProps,
|
|
48
|
+
WraperRouterProviderProps: props,
|
|
49
|
+
router,
|
|
50
|
+
});
|
|
51
|
+
const RouterProvider = (ReactRouterDom as any)['Router' + 'Provider'];
|
|
52
|
+
const createMemoryRouter = (ReactRouterDom as any)['create' + 'MemoryRouter'];
|
|
53
|
+
const createBrowserRouter = (ReactRouterDom as any)[
|
|
54
|
+
'create' + 'BrowserRouter'
|
|
55
|
+
];
|
|
56
|
+
if (!routerContextProps) return <RouterProvider {...props} />;
|
|
57
|
+
|
|
58
|
+
if (routerContextProps.memoryRoute) {
|
|
59
|
+
const MemeoryRouterInstance = createMemoryRouter(routers, {
|
|
60
|
+
initialEntries: [routerContextProps?.memoryRoute.entryPath],
|
|
61
|
+
});
|
|
62
|
+
return <RouterProvider router={MemeoryRouterInstance} />;
|
|
63
|
+
} else {
|
|
64
|
+
const BrowserRouterInstance = createBrowserRouter(routers, {
|
|
65
|
+
basename: routerContextProps.basename,
|
|
66
|
+
future: router.future,
|
|
67
|
+
window: router.window,
|
|
68
|
+
});
|
|
69
|
+
return <RouterProvider {...propsRes} router={BrowserRouterInstance} />;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export * from 'react-router-dom/dist/index.js';
|
|
74
|
+
|
|
75
|
+
export { WraperRouter as BrowserRouter };
|
|
76
|
+
export { WraperRouterProvider as RouterProvider };
|
package/src/router.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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
|
+
|
|
4
5
|
import { RouterContext } from './context';
|
|
5
6
|
import { LoggerInstance } from './utils';
|
|
6
7
|
|
|
@@ -52,6 +53,7 @@ function WraperRouterProvider(
|
|
|
52
53
|
const createBrowserRouter = (ReactRouterDom as any)[
|
|
53
54
|
'create' + 'BrowserRouter'
|
|
54
55
|
];
|
|
56
|
+
|
|
55
57
|
if (!routerContextProps) return <RouterProvider {...props} />;
|
|
56
58
|
|
|
57
59
|
if (routerContextProps.memoryRoute) {
|
package/vite.config.ts
CHANGED
|
@@ -22,6 +22,8 @@ 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'),
|
|
25
27
|
},
|
|
26
28
|
formats: ['cjs', 'es'],
|
|
27
29
|
fileName: (format, entryName) => `${entryName}.${format}.js`,
|
|
@@ -32,6 +34,8 @@ export default defineConfig({
|
|
|
32
34
|
'@remix-run/router',
|
|
33
35
|
'react-router',
|
|
34
36
|
'react-router-dom/',
|
|
37
|
+
'react-router-dom/index.js',
|
|
38
|
+
'react-router-dom/dist/index.js',
|
|
35
39
|
],
|
|
36
40
|
},
|
|
37
41
|
minify: false,
|