@modern-js/plugin-router-v5 2.4.0 → 2.4.1-beta.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/modern/runtime/plugin.js +3 -2
- package/dist/js/modern/runtime/utils.js +3 -0
- package/dist/js/node/runtime/plugin.js +3 -2
- package/dist/js/node/runtime/utils.js +3 -0
- package/dist/js/treeshaking/cli/index.js +2 -2
- package/dist/js/treeshaking/runtime/plugin.js +5 -5
- package/dist/js/treeshaking/runtime/utils.js +8 -5
- package/dist/types/runtime/plugin.d.ts +2 -0
- package/dist/types/runtime/utils.d.ts +1 -1
- package/package.json +6 -6
@@ -37,6 +37,7 @@ const routerPlugin = ({
|
|
37
37
|
history: customHistory,
|
38
38
|
supportHtml5History = true,
|
39
39
|
routesConfig,
|
40
|
+
createRoutes,
|
40
41
|
historyOptions = {}
|
41
42
|
}) => {
|
42
43
|
const isBrow = isBrowser();
|
@@ -62,7 +63,7 @@ const routerPlugin = ({
|
|
62
63
|
return (props) => /* @__PURE__ */ jsx(Router, {
|
63
64
|
history,
|
64
65
|
children: /* @__PURE__ */ jsx(App, __spreadProps(__spreadValues({}, props), {
|
65
|
-
children:
|
66
|
+
children: createRoutes ? createRoutes() : renderRoutes(routesConfig, props)
|
66
67
|
}))
|
67
68
|
});
|
68
69
|
}
|
@@ -79,7 +80,7 @@ const routerPlugin = ({
|
|
79
80
|
location: location2,
|
80
81
|
context: routerContext,
|
81
82
|
children: /* @__PURE__ */ jsx(App, __spreadProps(__spreadValues({}, props), {
|
82
|
-
children:
|
83
|
+
children: createRoutes ? createRoutes() : renderRoutes(routesConfig, props)
|
83
84
|
}))
|
84
85
|
});
|
85
86
|
};
|
@@ -30,6 +30,9 @@ import { jsx } from "react/jsx-runtime";
|
|
30
30
|
import { Route, matchPath } from "react-router-dom";
|
31
31
|
import { DefaultNotFound } from "./DefaultNotFound";
|
32
32
|
function renderRoutes(routesConfig, extraProps = {}) {
|
33
|
+
if (!routesConfig) {
|
34
|
+
return null;
|
35
|
+
}
|
33
36
|
const Layout = (_a) => {
|
34
37
|
var _b = _a, { Component } = _b, props = __objRest(_b, ["Component"]);
|
35
38
|
const GlobalLayout = routesConfig == null ? void 0 : routesConfig.globalApp;
|
@@ -55,6 +55,7 @@ const routerPlugin = ({
|
|
55
55
|
history: customHistory,
|
56
56
|
supportHtml5History = true,
|
57
57
|
routesConfig,
|
58
|
+
createRoutes,
|
58
59
|
historyOptions = {}
|
59
60
|
}) => {
|
60
61
|
const isBrow = (0, import_runtime.isBrowser)();
|
@@ -80,7 +81,7 @@ const routerPlugin = ({
|
|
80
81
|
return (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Router, {
|
81
82
|
history,
|
82
83
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, __spreadProps(__spreadValues({}, props), {
|
83
|
-
children:
|
84
|
+
children: createRoutes ? createRoutes() : (0, import_utils.renderRoutes)(routesConfig, props)
|
84
85
|
}))
|
85
86
|
});
|
86
87
|
}
|
@@ -97,7 +98,7 @@ const routerPlugin = ({
|
|
97
98
|
location: location2,
|
98
99
|
context: routerContext,
|
99
100
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, __spreadProps(__spreadValues({}, props), {
|
100
|
-
children:
|
101
|
+
children: createRoutes ? createRoutes() : (0, import_utils.renderRoutes)(routesConfig, props)
|
101
102
|
}))
|
102
103
|
});
|
103
104
|
};
|
@@ -53,6 +53,9 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
53
53
|
var import_react_router_dom = require("react-router-dom");
|
54
54
|
var import_DefaultNotFound = require("./DefaultNotFound");
|
55
55
|
function renderRoutes(routesConfig, extraProps = {}) {
|
56
|
+
if (!routesConfig) {
|
57
|
+
return null;
|
58
|
+
}
|
56
59
|
const Layout = (_a) => {
|
57
60
|
var _b = _a, { Component } = _b, props = __objRest(_b, ["Component"]);
|
58
61
|
const GlobalLayout = routesConfig == null ? void 0 : routesConfig.globalApp;
|
@@ -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 {
|
@@ -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,15 @@ 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
93
|
children: /* @__PURE__ */ jsx(App, _objectSpreadProps(_objectSpread({}, props), {
|
94
|
-
children:
|
94
|
+
children: createRoutes ? createRoutes() : renderRoutes(routesConfig, props)
|
95
95
|
}))
|
96
96
|
});
|
97
97
|
};
|
@@ -109,7 +109,7 @@ var routerPlugin = function(param) {
|
|
109
109
|
location: location2,
|
110
110
|
context: routerContext,
|
111
111
|
children: /* @__PURE__ */ jsx(App, _objectSpreadProps(_objectSpread({}, props), {
|
112
|
-
children:
|
112
|
+
children: createRoutes ? createRoutes() : renderRoutes(routesConfig, props)
|
113
113
|
}))
|
114
114
|
});
|
115
115
|
};
|
@@ -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;
|
@@ -40,6 +40,7 @@ export type RouterConfig = Partial<HistoryConfig> & {
|
|
40
40
|
globalApp?: React.ComponentType<any>;
|
41
41
|
routes?: SingleRouteConfig[];
|
42
42
|
};
|
43
|
+
createRoutes?: () => JSX.Element;
|
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,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "2.4.0",
|
14
|
+
"version": "2.4.1-beta.0",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/types/cli/index.d.ts",
|
17
17
|
"main": "./dist/js/node/cli/index.js",
|
@@ -53,7 +53,7 @@
|
|
53
53
|
"hoist-non-react-statics": "^3.3.2",
|
54
54
|
"@types/history": "^4.7.9",
|
55
55
|
"@types/react-router-dom": "^5.1.8",
|
56
|
-
"@modern-js/utils": "2.4.0",
|
56
|
+
"@modern-js/utils": "2.4.1-beta.0",
|
57
57
|
"@modern-js/types": "2.4.0"
|
58
58
|
},
|
59
59
|
"peerDependencies": {
|
@@ -73,11 +73,11 @@
|
|
73
73
|
"@testing-library/react": "^13.4.0",
|
74
74
|
"@testing-library/react-hooks": "^8.0.1",
|
75
75
|
"@types/invariant": "^2.2.30",
|
76
|
-
"@modern-js/runtime": "2.4.0",
|
77
|
-
"@modern-js/core": "2.4.0",
|
78
|
-
"@modern-js/utils": "2.4.0",
|
76
|
+
"@modern-js/runtime": "2.4.1-beta.0",
|
77
|
+
"@modern-js/core": "2.4.1-beta.0",
|
78
|
+
"@modern-js/utils": "2.4.1-beta.0",
|
79
79
|
"@scripts/build": "2.4.0",
|
80
|
-
"@modern-js/app-tools": "
|
80
|
+
"@modern-js/app-tools": "3.0.0-beta.0",
|
81
81
|
"@scripts/jest-config": "2.4.0"
|
82
82
|
},
|
83
83
|
"sideEffects": false,
|