@appigram/react-code-split-ssr 1.2.11 → 1.2.13
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/lib/generate-routes.js
CHANGED
|
@@ -17,9 +17,12 @@ const generateRoutes = (options = {
|
|
|
17
17
|
throw new Error("options.routes must be an non-empty array");
|
|
18
18
|
}
|
|
19
19
|
const preload = options.routes.find((route) => !!matchPath(route.path, options.pathname));
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const preloadedElement = preload === undefined ? options.notFoundComp : preload.element;
|
|
21
|
+
// fallback to previous version
|
|
22
|
+
const preloadedComp = typeof preloadedElement === 'function' ?
|
|
23
|
+
yield preloadedElement().props.mod
|
|
24
|
+
:
|
|
25
|
+
yield preloadedElement.props.mod;
|
|
23
26
|
const renderElement = (path, bundle) => {
|
|
24
27
|
if (!preloadedComp)
|
|
25
28
|
return bundle;
|
|
@@ -27,7 +30,7 @@ const generateRoutes = (options = {
|
|
|
27
30
|
const Element = isRouteMatched ? preloadedComp.default : bundle;
|
|
28
31
|
return isRouteMatched ? _jsx(Element, {}) : Element;
|
|
29
32
|
};
|
|
30
|
-
return (_jsxs(Routes, { children: [
|
|
33
|
+
return (_jsxs(Routes, { children: [options.routes.map((props, i) => {
|
|
31
34
|
return (_jsx(Route, { path: props.path, element: renderElement(props.path, props.element) }, i));
|
|
32
35
|
}), _jsx(Route, { path: '*', element: renderElement(null, options.notFoundComp) }, 'nf')] }));
|
|
33
36
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appigram/react-code-split-ssr",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.13",
|
|
4
4
|
"description": "React code splitting with SSR",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"author": "Eugene Sysmanov",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@types/react": "^18.2.
|
|
25
|
+
"@types/react": "^18.2.33",
|
|
26
26
|
"@types/react-router-dom": "^5.3.3",
|
|
27
27
|
"tslint": "^6.1.3",
|
|
28
28
|
"tslint-react": "^5.0.0",
|
|
@@ -31,6 +31,6 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"react": "^18.2.0",
|
|
33
33
|
"react-dom": "^18.2.0",
|
|
34
|
-
"react-router-dom": "^6.
|
|
34
|
+
"react-router-dom": "^6.17.0"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/generate-routes.tsx
CHANGED
|
@@ -33,10 +33,13 @@ const generateRoutes = async (
|
|
|
33
33
|
(route) => !!matchPath(route.path, options.pathname)
|
|
34
34
|
);
|
|
35
35
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
const preloadedElement = preload === undefined ? options.notFoundComp : preload.element
|
|
37
|
+
|
|
38
|
+
// fallback to previous version
|
|
39
|
+
const preloadedComp: any = typeof preloadedElement === 'function' ?
|
|
40
|
+
await preloadedElement().props.mod
|
|
41
|
+
:
|
|
42
|
+
await preloadedElement.props.mod
|
|
40
43
|
|
|
41
44
|
const renderElement = (path: string, bundle: ReactElement) => {
|
|
42
45
|
if (!preloadedComp) return bundle;
|
|
@@ -47,7 +50,7 @@ const generateRoutes = async (
|
|
|
47
50
|
|
|
48
51
|
return (
|
|
49
52
|
<Routes>
|
|
50
|
-
{
|
|
53
|
+
{options.routes.map((props, i) => {
|
|
51
54
|
return (
|
|
52
55
|
<Route
|
|
53
56
|
key={i}
|