@modern-js/plugin-router-v5 2.34.0 → 2.35.1
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/cjs/cli/index.js +1 -2
- package/dist/cjs/runtime/plugin.js +7 -10
- package/dist/cjs/runtime/utils.js +6 -7
- package/dist/esm/cli/index.js +1 -2
- package/dist/esm/runtime/plugin.js +6 -9
- package/dist/esm/runtime/utils.js +6 -7
- package/dist/esm-node/cli/index.js +1 -2
- package/dist/esm-node/runtime/plugin.js +6 -9
- package/dist/esm-node/runtime/utils.js +6 -7
- package/package.json +11 -10
package/dist/cjs/cli/index.js
CHANGED
@@ -104,9 +104,8 @@ const routerPlugin = () => ({
|
|
104
104
|
addRuntimeExports() {
|
105
105
|
const userConfig = api.useResolvedConfigContext();
|
106
106
|
if ((0, _utils.isRouterV5)(userConfig)) {
|
107
|
-
var _routerExportsUtils;
|
108
107
|
pluginsExportsUtils.addExport(`export { default as router } from '@modern-js/plugin-router-v5/runtime'`);
|
109
|
-
|
108
|
+
routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport(`export * from '@modern-js/plugin-router-v5/runtime'`);
|
110
109
|
}
|
111
110
|
}
|
112
111
|
};
|
@@ -16,17 +16,16 @@ const _history = require("history");
|
|
16
16
|
const _reactrouterdom = require("react-router-dom");
|
17
17
|
const _hoistnonreactstatics = /* @__PURE__ */ _interop_require_default._(require("hoist-non-react-statics"));
|
18
18
|
const _runtime = require("@modern-js/runtime");
|
19
|
-
const
|
19
|
+
const _browser = require("@modern-js/runtime-utils/browser");
|
20
20
|
const _utils = require("./utils");
|
21
21
|
const _hooks = require("./hooks");
|
22
22
|
const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} }) => {
|
23
|
-
|
24
|
-
const originRoutes = ((_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : _routesConfig.routes) || [];
|
23
|
+
const originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
|
25
24
|
const isBrow = (0, _runtime.isBrowser)();
|
26
25
|
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
27
26
|
let routes = [];
|
28
27
|
if (isBrow) {
|
29
|
-
window._SERVER_DATA = (0,
|
28
|
+
window._SERVER_DATA = (0, _browser.parsedJSONFromElement)("__MODERN_SERVER_DATA__");
|
30
29
|
}
|
31
30
|
return {
|
32
31
|
name: "@modern-js/plugin-router",
|
@@ -50,7 +49,6 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
|
|
50
49
|
});
|
51
50
|
},
|
52
51
|
hoc: ({ App }, next) => {
|
53
|
-
var _routesConfig2;
|
54
52
|
const getRouteApp = () => {
|
55
53
|
if (isBrow) {
|
56
54
|
var _window__SERVER_DATA;
|
@@ -74,13 +72,12 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
|
|
74
72
|
};
|
75
73
|
}
|
76
74
|
return (props) => {
|
77
|
-
var _ssrContext, _ssrContext1, _request;
|
78
75
|
const runtimeContext = (0, _react.useContext)(_runtime.RuntimeReactContext);
|
79
76
|
const { ssrContext } = runtimeContext;
|
80
77
|
const location1 = (0, _utils.getLocation)(ssrContext);
|
81
|
-
const routerContext = (
|
82
|
-
const request =
|
83
|
-
const baseUrl =
|
78
|
+
const routerContext = (ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.redirection) || {};
|
79
|
+
const request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
|
80
|
+
const baseUrl = request === null || request === void 0 ? void 0 : request.baseUrl;
|
84
81
|
const basename = baseUrl === "/" ? (0, _utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
|
85
82
|
const runner = api.useHookRunners();
|
86
83
|
const routes2 = runner.modifyRoutes(originRoutes);
|
@@ -103,7 +100,7 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
|
|
103
100
|
if (App) {
|
104
101
|
RouteApp = (0, _hoistnonreactstatics.default)(RouteApp, App);
|
105
102
|
}
|
106
|
-
if (
|
103
|
+
if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
|
107
104
|
return next({
|
108
105
|
App: (0, _hoistnonreactstatics.default)(RouteApp, routesConfig.globalApp)
|
109
106
|
});
|
@@ -33,8 +33,7 @@ function renderRoutes(routesConfig, extraProps = {}) {
|
|
33
33
|
return null;
|
34
34
|
}
|
35
35
|
const Layout = ({ Component, ...props }) => {
|
36
|
-
|
37
|
-
const GlobalLayout = (_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : _routesConfig.globalApp;
|
36
|
+
const GlobalLayout = routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp;
|
38
37
|
if (!GlobalLayout) {
|
39
38
|
return /* @__PURE__ */ (0, _jsxruntime.jsx)(Component, {
|
40
39
|
...props
|
@@ -46,8 +45,8 @@ function renderRoutes(routesConfig, extraProps = {}) {
|
|
46
45
|
});
|
47
46
|
};
|
48
47
|
const findMatchedRoute = (pathname) => {
|
49
|
-
var _routesConfig_routes
|
50
|
-
return
|
48
|
+
var _routesConfig_routes;
|
49
|
+
return routesConfig === null || routesConfig === void 0 ? void 0 : (_routesConfig_routes = routesConfig.routes) === null || _routesConfig_routes === void 0 ? void 0 : _routesConfig_routes.find((route) => {
|
51
50
|
const info = (0, _reactrouterdom.matchPath)(pathname, {
|
52
51
|
path: route.path,
|
53
52
|
exact: route.exact,
|
@@ -77,9 +76,9 @@ function renderRoutes(routesConfig, extraProps = {}) {
|
|
77
76
|
});
|
78
77
|
}
|
79
78
|
function getLocation(serverContext) {
|
80
|
-
var
|
81
|
-
const { pathname, url } = (
|
82
|
-
const cleanUrl =
|
79
|
+
var _url_replace;
|
80
|
+
const { pathname, url } = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {};
|
81
|
+
const cleanUrl = url === null || url === void 0 ? void 0 : (_url_replace = url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
|
83
82
|
const index = (cleanUrl || "").indexOf(pathname);
|
84
83
|
if (index === -1) {
|
85
84
|
return pathname;
|
package/dist/esm/cli/index.js
CHANGED
@@ -96,9 +96,8 @@ export var routerPlugin = function() {
|
|
96
96
|
addRuntimeExports: function addRuntimeExports() {
|
97
97
|
var userConfig = api.useResolvedConfigContext();
|
98
98
|
if (isV5(userConfig)) {
|
99
|
-
var _routerExportsUtils;
|
100
99
|
pluginsExportsUtils.addExport("export { default as router } from '@modern-js/plugin-router-v5/runtime'");
|
101
|
-
|
100
|
+
routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport("export * from '@modern-js/plugin-router-v5/runtime'");
|
102
101
|
}
|
103
102
|
}
|
104
103
|
};
|
@@ -6,13 +6,12 @@ import { createBrowserHistory, createHashHistory } from "history";
|
|
6
6
|
import { Router, StaticRouter, useRouteMatch, useLocation } from "react-router-dom";
|
7
7
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
8
8
|
import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
|
9
|
-
import { parsedJSONFromElement } from "@modern-js/utils/
|
9
|
+
import { parsedJSONFromElement } from "@modern-js/runtime-utils/browser";
|
10
10
|
import { renderRoutes, getLocation, urlJoin } from "./utils";
|
11
11
|
import { modifyRoutesHook } from "./hooks";
|
12
12
|
export var routerPlugin = function(param) {
|
13
13
|
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;
|
14
|
-
var
|
15
|
-
var originRoutes = ((_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : _routesConfig.routes) || [];
|
14
|
+
var originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
|
16
15
|
var isBrow = isBrowser();
|
17
16
|
var select = function(pathname) {
|
18
17
|
return serverBase.find(function(baseUrl) {
|
@@ -47,7 +46,6 @@ export var routerPlugin = function(param) {
|
|
47
46
|
},
|
48
47
|
hoc: function(param2, next) {
|
49
48
|
var App = param2.App;
|
50
|
-
var _routesConfig2;
|
51
49
|
var getRouteApp = function() {
|
52
50
|
if (isBrow) {
|
53
51
|
var _window__SERVER_DATA;
|
@@ -69,13 +67,12 @@ export var routerPlugin = function(param) {
|
|
69
67
|
};
|
70
68
|
}
|
71
69
|
return function(props) {
|
72
|
-
var _ssrContext, _ssrContext1, _request;
|
73
70
|
var runtimeContext = useContext(RuntimeReactContext);
|
74
71
|
var ssrContext = runtimeContext.ssrContext;
|
75
72
|
var _$location = getLocation(ssrContext);
|
76
|
-
var routerContext = (
|
77
|
-
var request =
|
78
|
-
var baseUrl2 =
|
73
|
+
var routerContext = (ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.redirection) || {};
|
74
|
+
var request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
|
75
|
+
var baseUrl2 = request === null || request === void 0 ? void 0 : request.baseUrl;
|
79
76
|
var basename = baseUrl2 === "/" ? urlJoin(baseUrl2, historyOptions.basename) : baseUrl2;
|
80
77
|
var runner = api.useHookRunners();
|
81
78
|
var routes2 = runner.modifyRoutes(originRoutes);
|
@@ -96,7 +93,7 @@ export var routerPlugin = function(param) {
|
|
96
93
|
if (App) {
|
97
94
|
RouteApp = hoistNonReactStatics(RouteApp, App);
|
98
95
|
}
|
99
|
-
if (
|
96
|
+
if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
|
100
97
|
return next({
|
101
98
|
App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
|
102
99
|
});
|
@@ -12,8 +12,7 @@ export function renderRoutes(routesConfig) {
|
|
12
12
|
var Component = _param.Component, props = _object_without_properties(_param, [
|
13
13
|
"Component"
|
14
14
|
]);
|
15
|
-
var
|
16
|
-
var GlobalLayout = (_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : _routesConfig.globalApp;
|
15
|
+
var GlobalLayout = routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp;
|
17
16
|
if (!GlobalLayout) {
|
18
17
|
return /* @__PURE__ */ _jsx(Component, _object_spread({}, props));
|
19
18
|
}
|
@@ -22,8 +21,8 @@ export function renderRoutes(routesConfig) {
|
|
22
21
|
}, props));
|
23
22
|
};
|
24
23
|
var findMatchedRoute = function(pathname) {
|
25
|
-
var _routesConfig_routes
|
26
|
-
return
|
24
|
+
var _routesConfig_routes;
|
25
|
+
return routesConfig === null || routesConfig === void 0 ? void 0 : (_routesConfig_routes = routesConfig.routes) === null || _routesConfig_routes === void 0 ? void 0 : _routesConfig_routes.find(function(route) {
|
27
26
|
var info = matchPath(pathname, {
|
28
27
|
path: route.path,
|
29
28
|
exact: route.exact,
|
@@ -53,9 +52,9 @@ export function renderRoutes(routesConfig) {
|
|
53
52
|
});
|
54
53
|
}
|
55
54
|
export function getLocation(serverContext) {
|
56
|
-
var
|
57
|
-
var _ref = (
|
58
|
-
var cleanUrl =
|
55
|
+
var _url_replace;
|
56
|
+
var _ref = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {}, pathname = _ref.pathname, url = _ref.url;
|
57
|
+
var cleanUrl = url === null || url === void 0 ? void 0 : (_url_replace = url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
|
59
58
|
var index = (cleanUrl || "").indexOf(pathname);
|
60
59
|
if (index === -1) {
|
61
60
|
return pathname;
|
@@ -85,9 +85,8 @@ export const routerPlugin = () => ({
|
|
85
85
|
addRuntimeExports() {
|
86
86
|
const userConfig = api.useResolvedConfigContext();
|
87
87
|
if (isV5(userConfig)) {
|
88
|
-
var _routerExportsUtils;
|
89
88
|
pluginsExportsUtils.addExport(`export { default as router } from '@modern-js/plugin-router-v5/runtime'`);
|
90
|
-
|
89
|
+
routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport(`export * from '@modern-js/plugin-router-v5/runtime'`);
|
91
90
|
}
|
92
91
|
}
|
93
92
|
};
|
@@ -4,12 +4,11 @@ import { createBrowserHistory, createHashHistory } from "history";
|
|
4
4
|
import { Router, StaticRouter, useRouteMatch, useLocation } from "react-router-dom";
|
5
5
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
6
6
|
import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
|
7
|
-
import { parsedJSONFromElement } from "@modern-js/utils/
|
7
|
+
import { parsedJSONFromElement } from "@modern-js/runtime-utils/browser";
|
8
8
|
import { renderRoutes, getLocation, urlJoin } from "./utils";
|
9
9
|
import { modifyRoutesHook } from "./hooks";
|
10
10
|
export const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} }) => {
|
11
|
-
|
12
|
-
const originRoutes = ((_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : _routesConfig.routes) || [];
|
11
|
+
const originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
|
13
12
|
const isBrow = isBrowser();
|
14
13
|
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
15
14
|
let routes = [];
|
@@ -38,7 +37,6 @@ export const routerPlugin = ({ serverBase = [], history: customHistory, supportH
|
|
38
37
|
});
|
39
38
|
},
|
40
39
|
hoc: ({ App }, next) => {
|
41
|
-
var _routesConfig2;
|
42
40
|
const getRouteApp = () => {
|
43
41
|
if (isBrow) {
|
44
42
|
var _window__SERVER_DATA;
|
@@ -62,13 +60,12 @@ export const routerPlugin = ({ serverBase = [], history: customHistory, supportH
|
|
62
60
|
};
|
63
61
|
}
|
64
62
|
return (props) => {
|
65
|
-
var _ssrContext, _ssrContext1, _request;
|
66
63
|
const runtimeContext = useContext(RuntimeReactContext);
|
67
64
|
const { ssrContext } = runtimeContext;
|
68
65
|
const location1 = getLocation(ssrContext);
|
69
|
-
const routerContext = (
|
70
|
-
const request =
|
71
|
-
const baseUrl =
|
66
|
+
const routerContext = (ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.redirection) || {};
|
67
|
+
const request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
|
68
|
+
const baseUrl = request === null || request === void 0 ? void 0 : request.baseUrl;
|
72
69
|
const basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
|
73
70
|
const runner = api.useHookRunners();
|
74
71
|
const routes2 = runner.modifyRoutes(originRoutes);
|
@@ -91,7 +88,7 @@ export const routerPlugin = ({ serverBase = [], history: customHistory, supportH
|
|
91
88
|
if (App) {
|
92
89
|
RouteApp = hoistNonReactStatics(RouteApp, App);
|
93
90
|
}
|
94
|
-
if (
|
91
|
+
if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
|
95
92
|
return next({
|
96
93
|
App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
|
97
94
|
});
|
@@ -6,8 +6,7 @@ export function renderRoutes(routesConfig, extraProps = {}) {
|
|
6
6
|
return null;
|
7
7
|
}
|
8
8
|
const Layout = ({ Component, ...props }) => {
|
9
|
-
|
10
|
-
const GlobalLayout = (_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : _routesConfig.globalApp;
|
9
|
+
const GlobalLayout = routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp;
|
11
10
|
if (!GlobalLayout) {
|
12
11
|
return /* @__PURE__ */ _jsx(Component, {
|
13
12
|
...props
|
@@ -19,8 +18,8 @@ export function renderRoutes(routesConfig, extraProps = {}) {
|
|
19
18
|
});
|
20
19
|
};
|
21
20
|
const findMatchedRoute = (pathname) => {
|
22
|
-
var _routesConfig_routes
|
23
|
-
return
|
21
|
+
var _routesConfig_routes;
|
22
|
+
return routesConfig === null || routesConfig === void 0 ? void 0 : (_routesConfig_routes = routesConfig.routes) === null || _routesConfig_routes === void 0 ? void 0 : _routesConfig_routes.find((route) => {
|
24
23
|
const info = matchPath(pathname, {
|
25
24
|
path: route.path,
|
26
25
|
exact: route.exact,
|
@@ -50,9 +49,9 @@ export function renderRoutes(routesConfig, extraProps = {}) {
|
|
50
49
|
});
|
51
50
|
}
|
52
51
|
export function getLocation(serverContext) {
|
53
|
-
var
|
54
|
-
const { pathname, url } = (
|
55
|
-
const cleanUrl =
|
52
|
+
var _url_replace;
|
53
|
+
const { pathname, url } = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {};
|
54
|
+
const cleanUrl = url === null || url === void 0 ? void 0 : (_url_replace = url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
|
56
55
|
const index = (cleanUrl || "").indexOf(pathname);
|
57
56
|
if (index === -1) {
|
58
57
|
return pathname;
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.
|
18
|
+
"version": "2.35.1",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/types/cli/index.d.ts",
|
21
21
|
"main": "./dist/cjs/cli/index.js",
|
@@ -60,9 +60,9 @@
|
|
60
60
|
"hoist-non-react-statics": "^3.3.2",
|
61
61
|
"react-router-dom": "^5.3.4",
|
62
62
|
"@swc/helpers": "0.5.1",
|
63
|
-
"@modern-js/plugin": "2.
|
64
|
-
"@modern-js/types": "2.
|
65
|
-
"@modern-js/utils": "2.
|
63
|
+
"@modern-js/plugin": "2.35.1",
|
64
|
+
"@modern-js/types": "2.35.1",
|
65
|
+
"@modern-js/utils": "2.35.1"
|
66
66
|
},
|
67
67
|
"peerDependencies": {
|
68
68
|
"react": ">=17",
|
@@ -78,12 +78,13 @@
|
|
78
78
|
"react-dom": "^18",
|
79
79
|
"ts-jest": "^29.1.0",
|
80
80
|
"typescript": "^5",
|
81
|
-
"@modern-js/app-tools": "2.
|
82
|
-
"@modern-js/core": "2.
|
83
|
-
"@modern-js/runtime": "2.
|
84
|
-
"@modern-js/utils": "2.
|
85
|
-
"@
|
86
|
-
"@scripts/jest-config": "2.
|
81
|
+
"@modern-js/app-tools": "2.35.1",
|
82
|
+
"@modern-js/core": "2.35.1",
|
83
|
+
"@modern-js/runtime": "2.35.1",
|
84
|
+
"@modern-js/utils": "2.35.1",
|
85
|
+
"@modern-js/runtime-utils": "2.35.1",
|
86
|
+
"@scripts/jest-config": "2.35.1",
|
87
|
+
"@scripts/build": "2.35.1"
|
87
88
|
},
|
88
89
|
"sideEffects": false,
|
89
90
|
"publishConfig": {
|