@modern-js/plugin-router-v5 2.18.1 → 2.19.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/CHANGELOG.md +9 -0
- package/dist/cjs/runtime/hooks.js +10 -0
- package/dist/cjs/runtime/plugin.js +24 -11
- package/dist/esm/runtime/hooks.js +3 -0
- package/dist/esm/runtime/plugin.js +12 -1
- package/dist/esm-node/runtime/hooks.js +3 -0
- package/dist/esm-node/runtime/plugin.js +24 -11
- package/dist/types/runtime/hooks.d.ts +5 -0
- package/package.json +10 -9
package/CHANGELOG.md
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "modifyRoutesHook", {
|
6
|
+
enumerable: true,
|
7
|
+
get: () => modifyRoutesHook
|
8
|
+
});
|
9
|
+
const _plugin = require("@modern-js/plugin");
|
10
|
+
const modifyRoutesHook = (0, _plugin.createWaterfall)();
|
@@ -14,6 +14,7 @@ const _hoistnonreactstatics = /* @__PURE__ */ _interop_require_default(require("
|
|
14
14
|
const _runtime = require("@modern-js/runtime");
|
15
15
|
const _runtimebrowser = require("@modern-js/utils/runtime-browser");
|
16
16
|
const _utils = require("./utils");
|
17
|
+
const _hooks = require("./hooks");
|
17
18
|
function _interop_require_default(obj) {
|
18
19
|
return obj && obj.__esModule ? obj : {
|
19
20
|
default: obj
|
@@ -60,6 +61,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
60
61
|
return newObj;
|
61
62
|
}
|
62
63
|
const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} }) => {
|
64
|
+
const originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
|
63
65
|
const isBrow = (0, _runtime.isBrowser)();
|
64
66
|
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
65
67
|
if (isBrow) {
|
@@ -67,7 +69,10 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
|
|
67
69
|
}
|
68
70
|
return {
|
69
71
|
name: "@modern-js/plugin-router",
|
70
|
-
|
72
|
+
registerHook: {
|
73
|
+
modifyRoutes: _hooks.modifyRoutesHook
|
74
|
+
},
|
75
|
+
setup: (api) => {
|
71
76
|
return {
|
72
77
|
init({ context }, next) {
|
73
78
|
context.router = {
|
@@ -85,16 +90,21 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
|
|
85
90
|
const baseUrl = ((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname);
|
86
91
|
historyOptions.basename = baseUrl === "/" ? (0, _utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
|
87
92
|
const history = customHistory || (supportHtml5History ? (0, _history.createBrowserHistory)(historyOptions) : (0, _history.createHashHistory)(historyOptions));
|
88
|
-
return (props) =>
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
93
|
+
return (props) => {
|
94
|
+
const runner = api.useHookRunners();
|
95
|
+
const routes = runner.modifyRoutes(originRoutes);
|
96
|
+
routesConfig && (routesConfig.routes = routes);
|
97
|
+
return /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.Router, {
|
98
|
+
history,
|
99
|
+
children: createRoutes ? /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
100
|
+
...props,
|
101
|
+
Component: createRoutes()
|
102
|
+
}) : /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
103
|
+
...props,
|
104
|
+
children: (0, _utils.renderRoutes)(routesConfig, props)
|
105
|
+
})
|
106
|
+
});
|
107
|
+
};
|
98
108
|
}
|
99
109
|
return (props) => {
|
100
110
|
const runtimeContext = (0, _react.useContext)(_runtime.RuntimeReactContext);
|
@@ -104,6 +114,9 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
|
|
104
114
|
const request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
|
105
115
|
const baseUrl = request === null || request === void 0 ? void 0 : request.baseUrl;
|
106
116
|
const basename = baseUrl === "/" ? (0, _utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
|
117
|
+
const runner = api.useHookRunners();
|
118
|
+
const routes = runner.modifyRoutes(originRoutes);
|
119
|
+
routesConfig && (routesConfig.routes = routes);
|
107
120
|
return /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.StaticRouter, {
|
108
121
|
basename: basename === "/" ? "" : basename,
|
109
122
|
location: location1,
|
@@ -58,8 +58,10 @@ import hoistNonReactStatics from "hoist-non-react-statics";
|
|
58
58
|
import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
|
59
59
|
import { parsedJSONFromElement } from "@modern-js/utils/runtime-browser";
|
60
60
|
import { renderRoutes, getLocation, urlJoin } from "./utils";
|
61
|
+
import { modifyRoutesHook } from "./hooks";
|
61
62
|
export var routerPlugin = function(param) {
|
62
63
|
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;
|
64
|
+
var originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
|
63
65
|
var isBrow = isBrowser();
|
64
66
|
var select = function(pathname) {
|
65
67
|
return serverBase.find(function(baseUrl) {
|
@@ -71,7 +73,10 @@ export var routerPlugin = function(param) {
|
|
71
73
|
}
|
72
74
|
return {
|
73
75
|
name: "@modern-js/plugin-router",
|
74
|
-
|
76
|
+
registerHook: {
|
77
|
+
modifyRoutes: modifyRoutesHook
|
78
|
+
},
|
79
|
+
setup: function(api) {
|
75
80
|
return {
|
76
81
|
init: function init(param2, next) {
|
77
82
|
var context = param2.context;
|
@@ -92,6 +97,9 @@ export var routerPlugin = function(param) {
|
|
92
97
|
historyOptions.basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
|
93
98
|
var history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
|
94
99
|
return function(props) {
|
100
|
+
var runner = api.useHookRunners();
|
101
|
+
var routes = runner.modifyRoutes(originRoutes);
|
102
|
+
routesConfig && (routesConfig.routes = routes);
|
95
103
|
return /* @__PURE__ */ _jsx(Router, {
|
96
104
|
history: history,
|
97
105
|
children: createRoutes ? /* @__PURE__ */ _jsx(App, _object_spread_props(_object_spread({}, props), {
|
@@ -110,6 +118,9 @@ export var routerPlugin = function(param) {
|
|
110
118
|
var request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
|
111
119
|
var baseUrl2 = request === null || request === void 0 ? void 0 : request.baseUrl;
|
112
120
|
var basename = baseUrl2 === "/" ? urlJoin(baseUrl2, historyOptions.basename) : baseUrl2;
|
121
|
+
var runner = api.useHookRunners();
|
122
|
+
var routes = runner.modifyRoutes(originRoutes);
|
123
|
+
routesConfig && (routesConfig.routes = routes);
|
113
124
|
return /* @__PURE__ */ _jsx(StaticRouter, {
|
114
125
|
basename: basename === "/" ? "" : basename,
|
115
126
|
location: _$location,
|
@@ -6,7 +6,9 @@ import hoistNonReactStatics from "hoist-non-react-statics";
|
|
6
6
|
import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
|
7
7
|
import { parsedJSONFromElement } from "@modern-js/utils/runtime-browser";
|
8
8
|
import { renderRoutes, getLocation, urlJoin } from "./utils";
|
9
|
+
import { modifyRoutesHook } from "./hooks";
|
9
10
|
export const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} }) => {
|
11
|
+
const originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
|
10
12
|
const isBrow = isBrowser();
|
11
13
|
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
12
14
|
if (isBrow) {
|
@@ -14,7 +16,10 @@ export const routerPlugin = ({ serverBase = [], history: customHistory, supportH
|
|
14
16
|
}
|
15
17
|
return {
|
16
18
|
name: "@modern-js/plugin-router",
|
17
|
-
|
19
|
+
registerHook: {
|
20
|
+
modifyRoutes: modifyRoutesHook
|
21
|
+
},
|
22
|
+
setup: (api) => {
|
18
23
|
return {
|
19
24
|
init({ context }, next) {
|
20
25
|
context.router = {
|
@@ -32,16 +37,21 @@ export const routerPlugin = ({ serverBase = [], history: customHistory, supportH
|
|
32
37
|
const baseUrl = ((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname);
|
33
38
|
historyOptions.basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
|
34
39
|
const history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
|
35
|
-
return (props) =>
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
return (props) => {
|
41
|
+
const runner = api.useHookRunners();
|
42
|
+
const routes = runner.modifyRoutes(originRoutes);
|
43
|
+
routesConfig && (routesConfig.routes = routes);
|
44
|
+
return /* @__PURE__ */ _jsx(Router, {
|
45
|
+
history,
|
46
|
+
children: createRoutes ? /* @__PURE__ */ _jsx(App, {
|
47
|
+
...props,
|
48
|
+
Component: createRoutes()
|
49
|
+
}) : /* @__PURE__ */ _jsx(App, {
|
50
|
+
...props,
|
51
|
+
children: renderRoutes(routesConfig, props)
|
52
|
+
})
|
53
|
+
});
|
54
|
+
};
|
45
55
|
}
|
46
56
|
return (props) => {
|
47
57
|
const runtimeContext = useContext(RuntimeReactContext);
|
@@ -51,6 +61,9 @@ export const routerPlugin = ({ serverBase = [], history: customHistory, supportH
|
|
51
61
|
const request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
|
52
62
|
const baseUrl = request === null || request === void 0 ? void 0 : request.baseUrl;
|
53
63
|
const basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
|
64
|
+
const runner = api.useHookRunners();
|
65
|
+
const routes = runner.modifyRoutes(originRoutes);
|
66
|
+
routesConfig && (routesConfig.routes = routes);
|
54
67
|
return /* @__PURE__ */ _jsx(StaticRouter, {
|
55
68
|
basename: basename === "/" ? "" : basename,
|
56
69
|
location: location1,
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.
|
18
|
+
"version": "2.19.0",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/types/cli/index.d.ts",
|
21
21
|
"main": "./dist/cjs/cli/index.js",
|
@@ -59,8 +59,9 @@
|
|
59
59
|
"history": "^4.7.9",
|
60
60
|
"hoist-non-react-statics": "^3.3.2",
|
61
61
|
"react-router-dom": "^5.3.4",
|
62
|
-
"@modern-js/
|
63
|
-
"@modern-js/
|
62
|
+
"@modern-js/plugin": "2.19.0",
|
63
|
+
"@modern-js/types": "2.19.0",
|
64
|
+
"@modern-js/utils": "2.19.0"
|
64
65
|
},
|
65
66
|
"peerDependencies": {
|
66
67
|
"react": ">=17",
|
@@ -78,12 +79,12 @@
|
|
78
79
|
"react-dom": "^18",
|
79
80
|
"ts-jest": "^29.0.4",
|
80
81
|
"typescript": "^4",
|
81
|
-
"@modern-js/app-tools": "2.
|
82
|
-
"@modern-js/core": "2.
|
83
|
-
"@modern-js/runtime": "2.
|
84
|
-
"@modern-js/utils": "2.
|
85
|
-
"@scripts/build": "2.
|
86
|
-
"@scripts/jest-config": "2.
|
82
|
+
"@modern-js/app-tools": "2.19.0",
|
83
|
+
"@modern-js/core": "2.19.0",
|
84
|
+
"@modern-js/runtime": "2.19.0",
|
85
|
+
"@modern-js/utils": "2.19.0",
|
86
|
+
"@scripts/build": "2.19.0",
|
87
|
+
"@scripts/jest-config": "2.19.0"
|
87
88
|
},
|
88
89
|
"sideEffects": false,
|
89
90
|
"modernConfig": {},
|