@modern-js/plugin-router-v5 2.4.0 → 2.5.0
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/{js/node → cjs}/cli/index.js +4 -21
- package/dist/{js/modern → cjs}/cli/types.js +0 -0
- package/dist/{js/node → cjs}/index.js +0 -0
- package/dist/{js/node → cjs}/runtime/DefaultNotFound.js +0 -0
- package/dist/{js/node → cjs}/runtime/index.js +0 -0
- package/dist/{js/node → cjs}/runtime/plugin.js +15 -23
- package/dist/{js/node → cjs}/runtime/utils.js +16 -35
- package/dist/{js/treeshaking → esm}/cli/index.js +2 -2
- package/dist/{js/treeshaking → esm}/cli/types.js +0 -0
- package/dist/{js/treeshaking → esm}/index.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime/DefaultNotFound.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime/index.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime/plugin.js +11 -7
- package/dist/{js/treeshaking → esm}/runtime/utils.js +8 -5
- package/dist/{js/modern → esm-node}/cli/index.js +4 -23
- package/dist/{js/node → esm-node}/cli/types.js +0 -0
- package/dist/{js/modern → esm-node}/index.js +0 -0
- package/dist/{js/modern → esm-node}/runtime/DefaultNotFound.js +0 -0
- package/dist/{js/modern → esm-node}/runtime/index.js +0 -0
- package/dist/{js/modern → esm-node}/runtime/plugin.js +15 -25
- package/dist/{js/modern → esm-node}/runtime/utils.js +16 -37
- package/dist/types/runtime/plugin.d.ts +2 -0
- package/dist/types/runtime/utils.d.ts +1 -1
- package/package.json +14 -15
@@ -1,24 +1,7 @@
|
|
1
1
|
var __defProp = Object.defineProperty;
|
2
|
-
var __defProps = Object.defineProperties;
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
5
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
7
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
10
|
-
var __spreadValues = (a, b) => {
|
11
|
-
for (var prop in b || (b = {}))
|
12
|
-
if (__hasOwnProp.call(b, prop))
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
14
|
-
if (__getOwnPropSymbols)
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
16
|
-
if (__propIsEnum.call(b, prop))
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
18
|
-
}
|
19
|
-
return a;
|
20
|
-
};
|
21
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
22
5
|
var __export = (target, all) => {
|
23
6
|
for (var name in all)
|
24
7
|
__defProp(target, name, { get: all[name], enumerable: true });
|
@@ -110,11 +93,11 @@ var cli_default = () => ({
|
|
110
93
|
const serverBase = serverRoutes.filter((route) => route.entryName === entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
|
111
94
|
plugins.push({
|
112
95
|
name: PLUGIN_IDENTIFIER,
|
113
|
-
options: JSON.stringify(
|
114
|
-
serverBase
|
115
|
-
|
96
|
+
options: JSON.stringify({
|
97
|
+
serverBase,
|
98
|
+
...runtimeConfig.router,
|
116
99
|
routesConfig: fileSystemRoutes ? `{ ${ROUTES_IDENTIFIER}, globalApp: App }` : void 0
|
117
|
-
})
|
100
|
+
}).replace(
|
118
101
|
/"routesConfig"\s*:\s*"((\S|\s)+)"/g,
|
119
102
|
'"routesConfig": $1,'
|
120
103
|
)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,26 +1,9 @@
|
|
1
1
|
var __create = Object.create;
|
2
2
|
var __defProp = Object.defineProperty;
|
3
|
-
var __defProps = Object.defineProperties;
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
8
5
|
var __getProtoOf = Object.getPrototypeOf;
|
9
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
12
|
-
var __spreadValues = (a, b) => {
|
13
|
-
for (var prop in b || (b = {}))
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
16
|
-
if (__getOwnPropSymbols)
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
18
|
-
if (__propIsEnum.call(b, prop))
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
20
|
-
}
|
21
|
-
return a;
|
22
|
-
};
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
24
7
|
var __export = (target, all) => {
|
25
8
|
for (var name in all)
|
26
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
@@ -55,6 +38,7 @@ const routerPlugin = ({
|
|
55
38
|
history: customHistory,
|
56
39
|
supportHtml5History = true,
|
57
40
|
routesConfig,
|
41
|
+
createRoutes,
|
58
42
|
historyOptions = {}
|
59
43
|
}) => {
|
60
44
|
const isBrow = (0, import_runtime.isBrowser)();
|
@@ -79,9 +63,13 @@ const routerPlugin = ({
|
|
79
63
|
const history = customHistory || (supportHtml5History ? (0, import_history.createBrowserHistory)(historyOptions) : (0, import_history.createHashHistory)(historyOptions));
|
80
64
|
return (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Router, {
|
81
65
|
history,
|
82
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App,
|
83
|
-
|
84
|
-
|
66
|
+
children: createRoutes ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
|
67
|
+
...props,
|
68
|
+
Component: createRoutes()
|
69
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
|
70
|
+
...props,
|
71
|
+
children: (0, import_utils.renderRoutes)(routesConfig, props)
|
72
|
+
})
|
85
73
|
});
|
86
74
|
}
|
87
75
|
return (props) => {
|
@@ -96,9 +84,13 @@ const routerPlugin = ({
|
|
96
84
|
basename: basename === "/" ? "" : basename,
|
97
85
|
location: location2,
|
98
86
|
context: routerContext,
|
99
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App,
|
100
|
-
|
101
|
-
|
87
|
+
children: createRoutes ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
|
88
|
+
...props,
|
89
|
+
Component: createRoutes()
|
90
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
|
91
|
+
...props,
|
92
|
+
children: (0, import_utils.renderRoutes)(routesConfig, props)
|
93
|
+
})
|
102
94
|
});
|
103
95
|
};
|
104
96
|
};
|
@@ -1,33 +1,7 @@
|
|
1
1
|
var __defProp = Object.defineProperty;
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
5
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
8
|
-
var __spreadValues = (a, b) => {
|
9
|
-
for (var prop in b || (b = {}))
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
12
|
-
if (__getOwnPropSymbols)
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
14
|
-
if (__propIsEnum.call(b, prop))
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
16
|
-
}
|
17
|
-
return a;
|
18
|
-
};
|
19
|
-
var __objRest = (source, exclude) => {
|
20
|
-
var target = {};
|
21
|
-
for (var prop in source)
|
22
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
23
|
-
target[prop] = source[prop];
|
24
|
-
if (source != null && __getOwnPropSymbols)
|
25
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
26
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
27
|
-
target[prop] = source[prop];
|
28
|
-
}
|
29
|
-
return target;
|
30
|
-
};
|
31
5
|
var __export = (target, all) => {
|
32
6
|
for (var name in all)
|
33
7
|
__defProp(target, name, { get: all[name], enumerable: true });
|
@@ -53,15 +27,20 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
53
27
|
var import_react_router_dom = require("react-router-dom");
|
54
28
|
var import_DefaultNotFound = require("./DefaultNotFound");
|
55
29
|
function renderRoutes(routesConfig, extraProps = {}) {
|
56
|
-
|
57
|
-
|
30
|
+
if (!routesConfig) {
|
31
|
+
return null;
|
32
|
+
}
|
33
|
+
const Layout = ({ Component, ...props }) => {
|
58
34
|
const GlobalLayout = routesConfig == null ? void 0 : routesConfig.globalApp;
|
59
35
|
if (!GlobalLayout) {
|
60
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component,
|
36
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {
|
37
|
+
...props
|
38
|
+
});
|
61
39
|
}
|
62
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GlobalLayout,
|
63
|
-
Component
|
64
|
-
|
40
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GlobalLayout, {
|
41
|
+
Component,
|
42
|
+
...props
|
43
|
+
});
|
65
44
|
};
|
66
45
|
const findMatchedRoute = (pathname) => {
|
67
46
|
var _a;
|
@@ -85,9 +64,11 @@ function renderRoutes(routesConfig, extraProps = {}) {
|
|
85
64
|
path: matchedRoute.path,
|
86
65
|
exact: matchedRoute.exact,
|
87
66
|
sensitive: matchedRoute.sensitive,
|
88
|
-
render: (routeProps) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Layout,
|
89
|
-
Component: matchedRoute.component
|
90
|
-
|
67
|
+
render: (routeProps) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Layout, {
|
68
|
+
Component: matchedRoute.component,
|
69
|
+
...routeProps,
|
70
|
+
...extraProps
|
71
|
+
})
|
91
72
|
});
|
92
73
|
}
|
93
74
|
});
|
@@ -55,8 +55,8 @@ import "./types";
|
|
55
55
|
var PLUGIN_IDENTIFIER = "router";
|
56
56
|
var ROUTES_IDENTIFIER = "routes";
|
57
57
|
var isV5 = function(config) {
|
58
|
-
var
|
59
|
-
return typeof ((
|
58
|
+
var _config_runtime, _config_runtime1, _config_runtime_router;
|
59
|
+
return typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && (config === null || config === void 0 ? void 0 : (_config_runtime1 = config.runtime) === null || _config_runtime1 === void 0 ? void 0 : (_config_runtime_router = _config_runtime1.router) === null || _config_runtime_router === void 0 ? void 0 : _config_runtime_router.mode) === "react-router-5";
|
60
60
|
};
|
61
61
|
var cli_default = function() {
|
62
62
|
return {
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -58,7 +58,7 @@ import hoistNonReactStatics from "hoist-non-react-statics";
|
|
58
58
|
import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
|
59
59
|
import { renderRoutes, getLocation, urlJoin } from "./utils";
|
60
60
|
var routerPlugin = function(param) {
|
61
|
-
var
|
61
|
+
var _param_serverBase = param.serverBase, serverBase = _param_serverBase === void 0 ? [] : _param_serverBase, customHistory = param.history, _param_supportHtml5History = param.supportHtml5History, supportHtml5History = _param_supportHtml5History === void 0 ? true : _param_supportHtml5History, routesConfig = param.routesConfig, createRoutes = param.createRoutes, _param_historyOptions = param.historyOptions, historyOptions = _param_historyOptions === void 0 ? {} : _param_historyOptions;
|
62
62
|
var isBrow = isBrowser();
|
63
63
|
var select = function(pathname) {
|
64
64
|
return serverBase.find(function(baseUrl) {
|
@@ -83,15 +83,17 @@ var routerPlugin = function(param) {
|
|
83
83
|
var App = param.App;
|
84
84
|
var getRouteApp = function() {
|
85
85
|
if (isBrow) {
|
86
|
-
var
|
87
|
-
var baseUrl = ((
|
86
|
+
var _window__SERVER_DATA;
|
87
|
+
var baseUrl = ((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname);
|
88
88
|
historyOptions.basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
|
89
89
|
var history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
|
90
90
|
return function(props) {
|
91
91
|
return /* @__PURE__ */ jsx(Router, {
|
92
92
|
history: history,
|
93
|
-
children: /* @__PURE__ */ jsx(App, _objectSpreadProps(_objectSpread({}, props), {
|
94
|
-
|
93
|
+
children: createRoutes ? /* @__PURE__ */ jsx(App, _objectSpreadProps(_objectSpread({}, props), {
|
94
|
+
Component: createRoutes()
|
95
|
+
})) : /* @__PURE__ */ jsx(App, _objectSpreadProps(_objectSpread({}, props), {
|
96
|
+
children: renderRoutes(routesConfig, props)
|
95
97
|
}))
|
96
98
|
});
|
97
99
|
};
|
@@ -108,8 +110,10 @@ var routerPlugin = function(param) {
|
|
108
110
|
basename: basename === "/" ? "" : basename,
|
109
111
|
location: location2,
|
110
112
|
context: routerContext,
|
111
|
-
children: /* @__PURE__ */ jsx(App, _objectSpreadProps(_objectSpread({}, props), {
|
112
|
-
|
113
|
+
children: createRoutes ? /* @__PURE__ */ jsx(App, _objectSpreadProps(_objectSpread({}, props), {
|
114
|
+
Component: createRoutes()
|
115
|
+
})) : /* @__PURE__ */ jsx(App, _objectSpreadProps(_objectSpread({}, props), {
|
116
|
+
children: renderRoutes(routesConfig, props)
|
113
117
|
}))
|
114
118
|
});
|
115
119
|
};
|
@@ -58,6 +58,9 @@ import { Route, matchPath } from "react-router-dom";
|
|
58
58
|
import { DefaultNotFound } from "./DefaultNotFound";
|
59
59
|
function renderRoutes(routesConfig) {
|
60
60
|
var extraProps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
61
|
+
if (!routesConfig) {
|
62
|
+
return null;
|
63
|
+
}
|
61
64
|
var Layout = function(_param) {
|
62
65
|
var Component = _param.Component, props = _objectWithoutProperties(_param, [
|
63
66
|
"Component"
|
@@ -71,8 +74,8 @@ function renderRoutes(routesConfig) {
|
|
71
74
|
}, props));
|
72
75
|
};
|
73
76
|
var findMatchedRoute = function(pathname) {
|
74
|
-
var
|
75
|
-
return routesConfig === null || routesConfig === void 0 ? void 0 : (
|
77
|
+
var _routesConfig_routes;
|
78
|
+
return routesConfig === null || routesConfig === void 0 ? void 0 : (_routesConfig_routes = routesConfig.routes) === null || _routesConfig_routes === void 0 ? void 0 : _routesConfig_routes.find(function(route) {
|
76
79
|
var info = matchPath(pathname, {
|
77
80
|
path: route.path,
|
78
81
|
exact: route.exact,
|
@@ -102,9 +105,9 @@ function renderRoutes(routesConfig) {
|
|
102
105
|
});
|
103
106
|
}
|
104
107
|
function getLocation(serverContext) {
|
105
|
-
var
|
106
|
-
var
|
107
|
-
var cleanUrl = (
|
108
|
+
var _url_replace;
|
109
|
+
var _ref = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {}, pathname = _ref.pathname, url = _ref.url;
|
110
|
+
var cleanUrl = (_url_replace = url === null || url === void 0 ? void 0 : url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
|
108
111
|
var index = (cleanUrl || "").indexOf(pathname);
|
109
112
|
if (index === -1) {
|
110
113
|
return pathname;
|
@@ -1,22 +1,3 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __defProps = Object.defineProperties;
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
8
|
-
var __spreadValues = (a, b) => {
|
9
|
-
for (var prop in b || (b = {}))
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
12
|
-
if (__getOwnPropSymbols)
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
14
|
-
if (__propIsEnum.call(b, prop))
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
16
|
-
}
|
17
|
-
return a;
|
18
|
-
};
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
20
1
|
import {
|
21
2
|
getEntryOptions,
|
22
3
|
createRuntimeExportsUtils,
|
@@ -94,11 +75,11 @@ var cli_default = () => ({
|
|
94
75
|
const serverBase = serverRoutes.filter((route) => route.entryName === entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
|
95
76
|
plugins.push({
|
96
77
|
name: PLUGIN_IDENTIFIER,
|
97
|
-
options: JSON.stringify(
|
98
|
-
serverBase
|
99
|
-
|
78
|
+
options: JSON.stringify({
|
79
|
+
serverBase,
|
80
|
+
...runtimeConfig.router,
|
100
81
|
routesConfig: fileSystemRoutes ? `{ ${ROUTES_IDENTIFIER}, globalApp: App }` : void 0
|
101
|
-
})
|
82
|
+
}).replace(
|
102
83
|
/"routesConfig"\s*:\s*"((\S|\s)+)"/g,
|
103
84
|
'"routesConfig": $1,'
|
104
85
|
)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,22 +1,3 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __defProps = Object.defineProperties;
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
8
|
-
var __spreadValues = (a, b) => {
|
9
|
-
for (var prop in b || (b = {}))
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
12
|
-
if (__getOwnPropSymbols)
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
14
|
-
if (__propIsEnum.call(b, prop))
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
16
|
-
}
|
17
|
-
return a;
|
18
|
-
};
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
20
1
|
import { jsx } from "react/jsx-runtime";
|
21
2
|
import { useContext } from "react";
|
22
3
|
import {
|
@@ -37,6 +18,7 @@ const routerPlugin = ({
|
|
37
18
|
history: customHistory,
|
38
19
|
supportHtml5History = true,
|
39
20
|
routesConfig,
|
21
|
+
createRoutes,
|
40
22
|
historyOptions = {}
|
41
23
|
}) => {
|
42
24
|
const isBrow = isBrowser();
|
@@ -61,9 +43,13 @@ const routerPlugin = ({
|
|
61
43
|
const history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
|
62
44
|
return (props) => /* @__PURE__ */ jsx(Router, {
|
63
45
|
history,
|
64
|
-
children: /* @__PURE__ */ jsx(App,
|
65
|
-
|
66
|
-
|
46
|
+
children: createRoutes ? /* @__PURE__ */ jsx(App, {
|
47
|
+
...props,
|
48
|
+
Component: createRoutes()
|
49
|
+
}) : /* @__PURE__ */ jsx(App, {
|
50
|
+
...props,
|
51
|
+
children: renderRoutes(routesConfig, props)
|
52
|
+
})
|
67
53
|
});
|
68
54
|
}
|
69
55
|
return (props) => {
|
@@ -78,9 +64,13 @@ const routerPlugin = ({
|
|
78
64
|
basename: basename === "/" ? "" : basename,
|
79
65
|
location: location2,
|
80
66
|
context: routerContext,
|
81
|
-
children: /* @__PURE__ */ jsx(App,
|
82
|
-
|
83
|
-
|
67
|
+
children: createRoutes ? /* @__PURE__ */ jsx(App, {
|
68
|
+
...props,
|
69
|
+
Component: createRoutes()
|
70
|
+
}) : /* @__PURE__ */ jsx(App, {
|
71
|
+
...props,
|
72
|
+
children: renderRoutes(routesConfig, props)
|
73
|
+
})
|
84
74
|
});
|
85
75
|
};
|
86
76
|
};
|
@@ -1,44 +1,21 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
6
|
-
var __spreadValues = (a, b) => {
|
7
|
-
for (var prop in b || (b = {}))
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
10
|
-
if (__getOwnPropSymbols)
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
12
|
-
if (__propIsEnum.call(b, prop))
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
14
|
-
}
|
15
|
-
return a;
|
16
|
-
};
|
17
|
-
var __objRest = (source, exclude) => {
|
18
|
-
var target = {};
|
19
|
-
for (var prop in source)
|
20
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
21
|
-
target[prop] = source[prop];
|
22
|
-
if (source != null && __getOwnPropSymbols)
|
23
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
24
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
25
|
-
target[prop] = source[prop];
|
26
|
-
}
|
27
|
-
return target;
|
28
|
-
};
|
29
1
|
import { jsx } from "react/jsx-runtime";
|
30
2
|
import { Route, matchPath } from "react-router-dom";
|
31
3
|
import { DefaultNotFound } from "./DefaultNotFound";
|
32
4
|
function renderRoutes(routesConfig, extraProps = {}) {
|
33
|
-
|
34
|
-
|
5
|
+
if (!routesConfig) {
|
6
|
+
return null;
|
7
|
+
}
|
8
|
+
const Layout = ({ Component, ...props }) => {
|
35
9
|
const GlobalLayout = routesConfig == null ? void 0 : routesConfig.globalApp;
|
36
10
|
if (!GlobalLayout) {
|
37
|
-
return /* @__PURE__ */ jsx(Component,
|
11
|
+
return /* @__PURE__ */ jsx(Component, {
|
12
|
+
...props
|
13
|
+
});
|
38
14
|
}
|
39
|
-
return /* @__PURE__ */ jsx(GlobalLayout,
|
40
|
-
Component
|
41
|
-
|
15
|
+
return /* @__PURE__ */ jsx(GlobalLayout, {
|
16
|
+
Component,
|
17
|
+
...props
|
18
|
+
});
|
42
19
|
};
|
43
20
|
const findMatchedRoute = (pathname) => {
|
44
21
|
var _a;
|
@@ -62,9 +39,11 @@ function renderRoutes(routesConfig, extraProps = {}) {
|
|
62
39
|
path: matchedRoute.path,
|
63
40
|
exact: matchedRoute.exact,
|
64
41
|
sensitive: matchedRoute.sensitive,
|
65
|
-
render: (routeProps) => /* @__PURE__ */ jsx(Layout,
|
66
|
-
Component: matchedRoute.component
|
67
|
-
|
42
|
+
render: (routeProps) => /* @__PURE__ */ jsx(Layout, {
|
43
|
+
Component: matchedRoute.component,
|
44
|
+
...routeProps,
|
45
|
+
...extraProps
|
46
|
+
})
|
68
47
|
});
|
69
48
|
}
|
70
49
|
});
|
@@ -40,6 +40,7 @@ export type RouterConfig = Partial<HistoryConfig> & {
|
|
40
40
|
globalApp?: React.ComponentType<any>;
|
41
41
|
routes?: SingleRouteConfig[];
|
42
42
|
};
|
43
|
+
createRoutes?: () => React.ComponentType<any> | null;
|
43
44
|
history?: History;
|
44
45
|
serverBase?: string[];
|
45
46
|
};
|
@@ -48,5 +49,6 @@ export declare const routerPlugin: ({
|
|
48
49
|
history: customHistory,
|
49
50
|
supportHtml5History,
|
50
51
|
routesConfig,
|
52
|
+
createRoutes,
|
51
53
|
historyOptions
|
52
54
|
}: RouterConfig) => Plugin;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import { RouterConfig } from './plugin';
|
3
|
-
export declare function renderRoutes(routesConfig
|
3
|
+
export declare function renderRoutes(routesConfig?: RouterConfig['routesConfig'], extraProps?: any): JSX.Element | null;
|
4
4
|
export declare function getLocation(serverContext: any): string;
|
5
5
|
export declare const urlJoin: (...parts: string[]) => string;
|
6
6
|
export declare function standardSlash(str: string): string;
|
package/package.json
CHANGED
@@ -11,24 +11,23 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "2.
|
14
|
+
"version": "2.5.0",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/types/cli/index.d.ts",
|
17
|
-
"main": "./dist/
|
18
|
-
"module": "./dist/
|
19
|
-
"jsnext:modern": "./dist/js/modern/cli/index.js",
|
17
|
+
"main": "./dist/cjs/cli/index.js",
|
18
|
+
"module": "./dist/esm/index.js",
|
20
19
|
"exports": {
|
21
20
|
".": {
|
22
21
|
"jsnext:source": "./src/cli/index.ts",
|
23
|
-
"default": "./dist/
|
22
|
+
"default": "./dist/cjs/cli/index.js"
|
24
23
|
},
|
25
24
|
"./runtime": {
|
26
25
|
"jsnext:source": "./src/runtime/index.ts",
|
27
|
-
"default": "./dist/
|
26
|
+
"default": "./dist/esm/runtime/index.js"
|
28
27
|
},
|
29
28
|
"./cli": {
|
30
29
|
"jsnext:source": "./src/cli/index.ts",
|
31
|
-
"default": "./dist/
|
30
|
+
"default": "./dist/cjs/cli/index.js"
|
32
31
|
}
|
33
32
|
},
|
34
33
|
"typesVersions": {
|
@@ -53,8 +52,8 @@
|
|
53
52
|
"hoist-non-react-statics": "^3.3.2",
|
54
53
|
"@types/history": "^4.7.9",
|
55
54
|
"@types/react-router-dom": "^5.1.8",
|
56
|
-
"@modern-js/utils": "2.
|
57
|
-
"@modern-js/types": "2.
|
55
|
+
"@modern-js/utils": "2.5.0",
|
56
|
+
"@modern-js/types": "2.5.0"
|
58
57
|
},
|
59
58
|
"peerDependencies": {
|
60
59
|
"react": ">=17",
|
@@ -73,12 +72,12 @@
|
|
73
72
|
"@testing-library/react": "^13.4.0",
|
74
73
|
"@testing-library/react-hooks": "^8.0.1",
|
75
74
|
"@types/invariant": "^2.2.30",
|
76
|
-
"@modern-js/runtime": "2.
|
77
|
-
"@modern-js/core": "2.
|
78
|
-
"@modern-js/utils": "2.
|
79
|
-
"@scripts/build": "2.
|
80
|
-
"@modern-js/app-tools": "2.
|
81
|
-
"@scripts/jest-config": "2.
|
75
|
+
"@modern-js/runtime": "2.5.0",
|
76
|
+
"@modern-js/core": "2.5.0",
|
77
|
+
"@modern-js/utils": "2.5.0",
|
78
|
+
"@scripts/build": "2.5.0",
|
79
|
+
"@modern-js/app-tools": "2.5.0",
|
80
|
+
"@scripts/jest-config": "2.5.0"
|
82
81
|
},
|
83
82
|
"sideEffects": false,
|
84
83
|
"modernConfig": {},
|