@modern-js/plugin-router-v5 2.37.1 → 2.37.2-fix.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/cjs/cli/index.js +37 -81
- package/dist/cjs/runtime/hooks.js +2 -2
- package/dist/cjs/runtime/index.js +4 -1
- package/dist/cjs/runtime/plugin.js +71 -93
- package/dist/esm/cli/index.js +44 -91
- package/dist/esm/runtime/hooks.js +2 -2
- package/dist/esm/runtime/index.js +3 -1
- package/dist/esm/runtime/plugin.js +72 -89
- package/dist/esm-node/cli/index.js +38 -82
- package/dist/esm-node/runtime/hooks.js +2 -2
- package/dist/esm-node/runtime/index.js +3 -1
- package/dist/esm-node/runtime/plugin.js +72 -84
- package/dist/types/cli/index.d.ts +3 -3
- package/dist/types/cli/types.d.ts +5 -5
- package/dist/types/index.d.ts +1 -1
- package/dist/types/runtime/DefaultNotFound.d.ts +2 -2
- package/dist/types/runtime/hooks.d.ts +4 -5
- package/dist/types/runtime/index.d.ts +3 -3
- package/dist/types/runtime/plugin.d.ts +34 -45
- package/dist/types/runtime/utils.d.ts +4 -4
- package/package.json +12 -13
@@ -1,108 +1,91 @@
|
|
1
1
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
2
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
3
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
4
|
-
import {
|
3
|
+
import { RuntimeReactContext, isBrowser } from "@meta/runtime";
|
4
|
+
import { getGlobalLayoutApp, getGlobalRoutes } from "@meta/runtime/context";
|
5
|
+
import { merge } from "@modern-js/runtime-utils/merge";
|
5
6
|
import { createBrowserHistory, createHashHistory } from "history";
|
6
|
-
import {
|
7
|
-
import
|
8
|
-
import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
|
9
|
-
import { parsedJSONFromElement } from "@modern-js/runtime-utils/browser";
|
10
|
-
import { renderRoutes, getLocation, urlJoin } from "./utils";
|
7
|
+
import { useContext } from "react";
|
8
|
+
import { Router, StaticRouter, useHistory, useLocation, useRouteMatch } from "react-router-dom";
|
11
9
|
import { modifyRoutesHook } from "./hooks";
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
var
|
16
|
-
var select = function(pathname) {
|
17
|
-
return serverBase.find(function(baseUrl) {
|
18
|
-
return pathname.search(baseUrl) === 0;
|
19
|
-
}) || "/";
|
20
|
-
};
|
21
|
-
var routes = [];
|
22
|
-
if (isBrow) {
|
23
|
-
window._SERVER_DATA = parsedJSONFromElement("__MODERN_SERVER_DATA__");
|
24
|
-
}
|
10
|
+
import { getLocation, renderRoutes, urlJoin } from "./utils";
|
11
|
+
var routes = [];
|
12
|
+
var routerPlugin = function() {
|
13
|
+
var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
25
14
|
return {
|
26
15
|
name: "@modern-js/plugin-router",
|
27
|
-
|
16
|
+
registryHooks: {
|
28
17
|
modifyRoutes: modifyRoutesHook
|
29
18
|
},
|
30
19
|
setup: function(api) {
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
return /* @__PURE__ */ _jsx(Router, {
|
60
|
-
history,
|
61
|
-
children: createRoutes ? /* @__PURE__ */ _jsx(App, _object_spread_props(_object_spread({}, props), {
|
62
|
-
Component: createRoutes()
|
63
|
-
})) : /* @__PURE__ */ _jsx(App, _object_spread_props(_object_spread({}, props), {
|
64
|
-
children: renderRoutes(routesConfig, props)
|
65
|
-
}))
|
66
|
-
});
|
67
|
-
};
|
68
|
-
}
|
20
|
+
api.onBeforeRender(function(context) {
|
21
|
+
context.router = {
|
22
|
+
useRouteMatch,
|
23
|
+
useLocation,
|
24
|
+
useHistory
|
25
|
+
};
|
26
|
+
Object.defineProperty(context, "routes", {
|
27
|
+
get: function get() {
|
28
|
+
return routes;
|
29
|
+
}
|
30
|
+
});
|
31
|
+
});
|
32
|
+
api.wrapRoot(function(App) {
|
33
|
+
var pluginConfig = api.getRuntimeConfig();
|
34
|
+
var _merge = merge(pluginConfig.router || {}, userConfig), _merge_serverBase = _merge.serverBase, serverBase = _merge_serverBase === void 0 ? [] : _merge_serverBase, customHistory = _merge.history, _merge_supportHtml5History = _merge.supportHtml5History, supportHtml5History = _merge_supportHtml5History === void 0 ? true : _merge_supportHtml5History, routesConfig = _merge.routesConfig, createRoutes = _merge.createRoutes, _merge_historyOptions = _merge.historyOptions, historyOptions = _merge_historyOptions === void 0 ? {} : _merge_historyOptions;
|
35
|
+
var finalRouteConfig = _object_spread({
|
36
|
+
routes: getGlobalRoutes(),
|
37
|
+
globalApp: getGlobalLayoutApp()
|
38
|
+
}, routesConfig);
|
39
|
+
var originRoutes = finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes;
|
40
|
+
var isBrow = isBrowser();
|
41
|
+
var select = function(pathname) {
|
42
|
+
return serverBase.find(function(baseUrl) {
|
43
|
+
return pathname.search(baseUrl) === 0;
|
44
|
+
}) || "/";
|
45
|
+
};
|
46
|
+
var getRouteApp = function() {
|
47
|
+
if (isBrow) {
|
69
48
|
return function(props) {
|
70
49
|
var runtimeContext = useContext(RuntimeReactContext);
|
71
|
-
var
|
72
|
-
var
|
73
|
-
|
74
|
-
var
|
75
|
-
var
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
basename: basename === "/" ? "" : basename,
|
82
|
-
location: _$location,
|
83
|
-
context: routerContext,
|
84
|
-
children: createRoutes ? /* @__PURE__ */ _jsx(App, _object_spread_props(_object_spread({}, props), {
|
50
|
+
var baseUrl = select(location.pathname).replace(/^\/*/, "/");
|
51
|
+
var basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || historyOptions.basename) : baseUrl;
|
52
|
+
historyOptions.basename = basename;
|
53
|
+
var history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
|
54
|
+
var hooks = api.getHooks();
|
55
|
+
routes = hooks.modifyRoutes.call(originRoutes);
|
56
|
+
finalRouteConfig && (finalRouteConfig.routes = routes);
|
57
|
+
return /* @__PURE__ */ _jsx(Router, {
|
58
|
+
history,
|
59
|
+
children: createRoutes ? /* @__PURE__ */ _jsx(App, {
|
85
60
|
Component: createRoutes()
|
86
|
-
})
|
87
|
-
children: renderRoutes(routesConfig, props)
|
88
|
-
}))
|
61
|
+
}) : App && !(finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes) ? /* @__PURE__ */ _jsx(App, _object_spread({}, props)) : renderRoutes(finalRouteConfig, props)
|
89
62
|
});
|
90
63
|
};
|
91
|
-
};
|
92
|
-
var RouteApp = getRouteApp();
|
93
|
-
if (App) {
|
94
|
-
RouteApp = hoistNonReactStatics(RouteApp, App);
|
95
64
|
}
|
96
|
-
|
97
|
-
|
98
|
-
|
65
|
+
return function(props) {
|
66
|
+
var _request_baseUrl;
|
67
|
+
var runtimeContext = useContext(RuntimeReactContext);
|
68
|
+
var ssrContext = runtimeContext.ssrContext;
|
69
|
+
var location1 = getLocation(ssrContext);
|
70
|
+
var routerContext = (ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.redirection) || {};
|
71
|
+
var request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
|
72
|
+
var baseUrl = request === null || request === void 0 ? void 0 : (_request_baseUrl = request.baseUrl) === null || _request_baseUrl === void 0 ? void 0 : _request_baseUrl.replace(/^\/*/, "/");
|
73
|
+
var basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || historyOptions.basename) : baseUrl;
|
74
|
+
var hooks = api.getHooks();
|
75
|
+
var routes2 = hooks.modifyRoutes.call(originRoutes);
|
76
|
+
finalRouteConfig && (finalRouteConfig.routes = routes2);
|
77
|
+
return /* @__PURE__ */ _jsx(StaticRouter, {
|
78
|
+
basename: basename === "/" ? "" : basename,
|
79
|
+
location: location1,
|
80
|
+
context: routerContext,
|
81
|
+
children: createRoutes ? /* @__PURE__ */ _jsx(App, _object_spread({
|
82
|
+
Component: createRoutes()
|
83
|
+
}, props)) : App && !(finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes) ? /* @__PURE__ */ _jsx(App, _object_spread({}, props)) : renderRoutes(finalRouteConfig, props)
|
99
84
|
});
|
100
|
-
}
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
}
|
105
|
-
};
|
85
|
+
};
|
86
|
+
};
|
87
|
+
return getRouteApp();
|
88
|
+
});
|
106
89
|
}
|
107
90
|
};
|
108
91
|
};
|
@@ -1,95 +1,51 @@
|
|
1
|
-
import {
|
1
|
+
import { createRuntimeExportsUtils, getEntryOptions } from "@modern-js/utils";
|
2
2
|
import "./types";
|
3
|
-
const PLUGIN_IDENTIFIER = "router";
|
4
|
-
const ROUTES_IDENTIFIER = "routes";
|
5
3
|
const routerPlugin = () => ({
|
6
4
|
name: "@modern-js/plugin-router-v5",
|
7
5
|
required: [
|
8
6
|
"@modern-js/runtime"
|
9
7
|
],
|
10
8
|
setup: (api) => {
|
11
|
-
const runtimeConfigMap = /* @__PURE__ */ new Map();
|
12
|
-
let pluginsExportsUtils;
|
13
9
|
let routerExportsUtils;
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
validateSchema() {
|
29
|
-
return [
|
30
|
-
{
|
31
|
-
target: "runtime.router",
|
32
|
-
schema: {
|
33
|
-
type: [
|
34
|
-
"boolean",
|
35
|
-
"object"
|
36
|
-
]
|
37
|
-
}
|
38
|
-
}
|
39
|
-
];
|
40
|
-
},
|
41
|
-
modifyEntryImports({ entrypoint, imports }) {
|
42
|
-
const { entryName, isMainEntry } = entrypoint;
|
43
|
-
const userConfig = api.useResolvedConfigContext();
|
44
|
-
const { packageName } = api.useAppContext();
|
45
|
-
const runtimeConfig = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
46
|
-
runtimeConfigMap.set(entryName, runtimeConfig);
|
47
|
-
if (isV5(userConfig)) {
|
48
|
-
imports.push({
|
49
|
-
value: "@modern-js/runtime/plugins",
|
50
|
-
specifiers: [
|
51
|
-
{
|
52
|
-
imported: PLUGIN_IDENTIFIER
|
53
|
-
}
|
54
|
-
]
|
55
|
-
});
|
56
|
-
} else {
|
57
|
-
throw new Error(`should enable runtime.router.mode for entry ${entryName}`);
|
10
|
+
api._internalRuntimePlugins(({ entrypoint, plugins }) => {
|
11
|
+
var _getEntryOptions;
|
12
|
+
const userConfig = api.getNormalizedConfig();
|
13
|
+
const { serverRoutes, metaName, packageName } = api.getAppContext();
|
14
|
+
const routerConfig = (_getEntryOptions = getEntryOptions(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.router;
|
15
|
+
const serverBase = serverRoutes.filter((route) => route.entryName === entrypoint.entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
|
16
|
+
plugins.push({
|
17
|
+
name: "router",
|
18
|
+
path: `@${metaName}/plugin-router-v5/runtime`,
|
19
|
+
config: typeof routerConfig === "boolean" ? {
|
20
|
+
serverBase
|
21
|
+
} : {
|
22
|
+
...routerConfig,
|
23
|
+
serverBase
|
58
24
|
}
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
}
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
options: JSON.stringify({
|
74
|
-
serverBase,
|
75
|
-
...runtimeConfig.router,
|
76
|
-
routesConfig: fileSystemRoutes ? `{ ${ROUTES_IDENTIFIER}, globalApp: App }` : void 0
|
77
|
-
}).replace(/"routesConfig"\s*:\s*"((\S|\s)+)"/g, '"routesConfig": $1,')
|
78
|
-
});
|
79
|
-
}
|
80
|
-
return {
|
81
|
-
entrypoint,
|
82
|
-
plugins
|
83
|
-
};
|
84
|
-
},
|
85
|
-
addRuntimeExports() {
|
86
|
-
const userConfig = api.useResolvedConfigContext();
|
87
|
-
if (isV5(userConfig)) {
|
88
|
-
pluginsExportsUtils.addExport(`export { default as router } from '@modern-js/plugin-router-v5/runtime'`);
|
89
|
-
routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport(`export * from '@modern-js/plugin-router-v5/runtime'`);
|
25
|
+
});
|
26
|
+
return {
|
27
|
+
entrypoint,
|
28
|
+
plugins
|
29
|
+
};
|
30
|
+
});
|
31
|
+
api.config(() => {
|
32
|
+
const { internalDirectory, metaName } = api.getAppContext();
|
33
|
+
routerExportsUtils = createRuntimeExportsUtils(internalDirectory, "router");
|
34
|
+
return {
|
35
|
+
source: {
|
36
|
+
alias: {
|
37
|
+
[`@${metaName}/runtime/router-v5`]: routerExportsUtils.getPath()
|
38
|
+
}
|
90
39
|
}
|
91
|
-
}
|
92
|
-
};
|
40
|
+
};
|
41
|
+
});
|
42
|
+
api.addRuntimeExports(() => {
|
43
|
+
const userConfig = api.getNormalizedConfig();
|
44
|
+
const { internalDirectory, metaName } = api.getAppContext();
|
45
|
+
const pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
|
46
|
+
pluginsExportsUtils.addExport(`export { default as router } from '@${metaName}/plugin-router-v5/runtime'`);
|
47
|
+
routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport(`export * from '@${metaName}/plugin-router-v5/runtime'`);
|
48
|
+
});
|
93
49
|
}
|
94
50
|
});
|
95
51
|
var cli_default = routerPlugin;
|
@@ -1,7 +1,9 @@
|
|
1
1
|
import { routerPlugin } from "./plugin";
|
2
|
+
import { routerPlugin as routerPlugin2 } from "./plugin";
|
2
3
|
var runtime_default = routerPlugin;
|
3
4
|
export * from "react-router-dom";
|
4
5
|
export * from "history";
|
5
6
|
export {
|
6
|
-
runtime_default as default
|
7
|
+
runtime_default as default,
|
8
|
+
routerPlugin2 as routerPlugin
|
7
9
|
};
|
@@ -1,103 +1,91 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import {
|
2
|
+
import { RuntimeReactContext, isBrowser } from "@meta/runtime";
|
3
|
+
import { getGlobalLayoutApp, getGlobalRoutes } from "@meta/runtime/context";
|
4
|
+
import { merge } from "@modern-js/runtime-utils/merge";
|
3
5
|
import { createBrowserHistory, createHashHistory } from "history";
|
4
|
-
import {
|
5
|
-
import
|
6
|
-
import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
|
7
|
-
import { parsedJSONFromElement } from "@modern-js/runtime-utils/browser";
|
8
|
-
import { renderRoutes, getLocation, urlJoin } from "./utils";
|
6
|
+
import { useContext } from "react";
|
7
|
+
import { Router, StaticRouter, useHistory, useLocation, useRouteMatch } from "react-router-dom";
|
9
8
|
import { modifyRoutesHook } from "./hooks";
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
14
|
-
let routes = [];
|
15
|
-
if (isBrow) {
|
16
|
-
window._SERVER_DATA = parsedJSONFromElement("__MODERN_SERVER_DATA__");
|
17
|
-
}
|
9
|
+
import { getLocation, renderRoutes, urlJoin } from "./utils";
|
10
|
+
let routes = [];
|
11
|
+
const routerPlugin = (userConfig = {}) => {
|
18
12
|
return {
|
19
13
|
name: "@modern-js/plugin-router",
|
20
|
-
|
14
|
+
registryHooks: {
|
21
15
|
modifyRoutes: modifyRoutesHook
|
22
16
|
},
|
23
17
|
setup: (api) => {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
},
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
routesConfig && (routesConfig.routes = routes);
|
50
|
-
return /* @__PURE__ */ _jsx(Router, {
|
51
|
-
history,
|
52
|
-
children: createRoutes ? /* @__PURE__ */ _jsx(App, {
|
53
|
-
...props,
|
54
|
-
Component: createRoutes()
|
55
|
-
}) : /* @__PURE__ */ _jsx(App, {
|
56
|
-
...props,
|
57
|
-
children: renderRoutes(routesConfig, props)
|
58
|
-
})
|
59
|
-
});
|
60
|
-
};
|
61
|
-
}
|
18
|
+
api.onBeforeRender((context) => {
|
19
|
+
context.router = {
|
20
|
+
useRouteMatch,
|
21
|
+
useLocation,
|
22
|
+
useHistory
|
23
|
+
};
|
24
|
+
Object.defineProperty(context, "routes", {
|
25
|
+
get() {
|
26
|
+
return routes;
|
27
|
+
}
|
28
|
+
});
|
29
|
+
});
|
30
|
+
api.wrapRoot((App) => {
|
31
|
+
const pluginConfig = api.getRuntimeConfig();
|
32
|
+
const { serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} } = merge(pluginConfig.router || {}, userConfig);
|
33
|
+
const finalRouteConfig = {
|
34
|
+
routes: getGlobalRoutes(),
|
35
|
+
globalApp: getGlobalLayoutApp(),
|
36
|
+
...routesConfig
|
37
|
+
};
|
38
|
+
const originRoutes = finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes;
|
39
|
+
const isBrow = isBrowser();
|
40
|
+
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
41
|
+
const getRouteApp = () => {
|
42
|
+
if (isBrow) {
|
62
43
|
return (props) => {
|
63
44
|
const runtimeContext = useContext(RuntimeReactContext);
|
64
|
-
const
|
65
|
-
const
|
66
|
-
|
67
|
-
const
|
68
|
-
const
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
return /* @__PURE__ */ _jsx(StaticRouter, {
|
74
|
-
basename: basename === "/" ? "" : basename,
|
75
|
-
location: location1,
|
76
|
-
context: routerContext,
|
45
|
+
const baseUrl = select(location.pathname).replace(/^\/*/, "/");
|
46
|
+
const basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || historyOptions.basename) : baseUrl;
|
47
|
+
historyOptions.basename = basename;
|
48
|
+
const history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
|
49
|
+
const hooks = api.getHooks();
|
50
|
+
routes = hooks.modifyRoutes.call(originRoutes);
|
51
|
+
finalRouteConfig && (finalRouteConfig.routes = routes);
|
52
|
+
return /* @__PURE__ */ _jsx(Router, {
|
53
|
+
history,
|
77
54
|
children: createRoutes ? /* @__PURE__ */ _jsx(App, {
|
78
|
-
...props,
|
79
55
|
Component: createRoutes()
|
80
|
-
}) : /* @__PURE__ */ _jsx(App, {
|
81
|
-
...props
|
82
|
-
|
83
|
-
})
|
56
|
+
}) : App && !(finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes) ? /* @__PURE__ */ _jsx(App, {
|
57
|
+
...props
|
58
|
+
}) : renderRoutes(finalRouteConfig, props)
|
84
59
|
});
|
85
60
|
};
|
86
|
-
};
|
87
|
-
let RouteApp = getRouteApp();
|
88
|
-
if (App) {
|
89
|
-
RouteApp = hoistNonReactStatics(RouteApp, App);
|
90
61
|
}
|
91
|
-
|
92
|
-
|
93
|
-
|
62
|
+
return (props) => {
|
63
|
+
var _request_baseUrl;
|
64
|
+
const runtimeContext = useContext(RuntimeReactContext);
|
65
|
+
const { ssrContext } = runtimeContext;
|
66
|
+
const location1 = getLocation(ssrContext);
|
67
|
+
const routerContext = (ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.redirection) || {};
|
68
|
+
const request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
|
69
|
+
const baseUrl = request === null || request === void 0 ? void 0 : (_request_baseUrl = request.baseUrl) === null || _request_baseUrl === void 0 ? void 0 : _request_baseUrl.replace(/^\/*/, "/");
|
70
|
+
const basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || historyOptions.basename) : baseUrl;
|
71
|
+
const hooks = api.getHooks();
|
72
|
+
const routes2 = hooks.modifyRoutes.call(originRoutes);
|
73
|
+
finalRouteConfig && (finalRouteConfig.routes = routes2);
|
74
|
+
return /* @__PURE__ */ _jsx(StaticRouter, {
|
75
|
+
basename: basename === "/" ? "" : basename,
|
76
|
+
location: location1,
|
77
|
+
context: routerContext,
|
78
|
+
children: createRoutes ? /* @__PURE__ */ _jsx(App, {
|
79
|
+
Component: createRoutes(),
|
80
|
+
...props
|
81
|
+
}) : App && !(finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes) ? /* @__PURE__ */ _jsx(App, {
|
82
|
+
...props
|
83
|
+
}) : renderRoutes(finalRouteConfig, props)
|
94
84
|
});
|
95
|
-
}
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
}
|
100
|
-
};
|
85
|
+
};
|
86
|
+
};
|
87
|
+
return getRouteApp();
|
88
|
+
});
|
101
89
|
}
|
102
90
|
};
|
103
91
|
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { AppTools,
|
1
|
+
import type { AppTools, CliPluginFuture } from '@modern-js/app-tools';
|
2
2
|
import './types';
|
3
|
-
export declare const routerPlugin: () =>
|
4
|
-
export default routerPlugin;
|
3
|
+
export declare const routerPlugin: () => CliPluginFuture<AppTools>;
|
4
|
+
export default routerPlugin;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { RouterConfig } from '../runtime/plugin';
|
1
|
+
import type { RouterConfig } from '../runtime/plugin';
|
2
2
|
declare module '@modern-js/app-tools' {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
}
|
3
|
+
interface RuntimeUserConfig {
|
4
|
+
router?: RouterConfig | boolean;
|
5
|
+
}
|
6
|
+
}
|
package/dist/types/index.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
export { default } from './runtime';
|
2
|
-
export * from './runtime';
|
2
|
+
export * from './runtime';
|
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
export declare const DefaultNotFound: () => JSX.Element;
|
1
|
+
import React from 'react';
|
2
|
+
export declare const DefaultNotFound: () => React.JSX.Element;
|
@@ -1,5 +1,4 @@
|
|
1
|
-
import { RouteProps } from 'react-router-dom';
|
2
|
-
|
3
|
-
|
4
|
-
}
|
5
|
-
export { modifyRoutesHook };
|
1
|
+
import type { RouteProps } from 'react-router-dom';
|
2
|
+
import type { SingleRouteConfig } from './plugin';
|
3
|
+
declare const modifyRoutesHook: import("@modern-js/plugin-v2").SyncHook<(routes: RouteProps[]) => SingleRouteConfig[]>;
|
4
|
+
export { modifyRoutesHook };
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { routerPlugin } from './plugin';
|
2
|
-
|
3
|
-
export
|
2
|
+
export type { SingleRouteConfig, HistoryConfig, RouterConfig, RouterExtendsHooks, } from './plugin';
|
3
|
+
export { routerPlugin } from './plugin';
|
4
4
|
export default routerPlugin;
|
5
5
|
export * from 'react-router-dom';
|
6
|
-
export * from 'history';
|
6
|
+
export * from 'history';
|