@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.
@@ -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 { useContext } from "react";
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 { Router, StaticRouter, useRouteMatch, useLocation } from "react-router-dom";
7
- import hoistNonReactStatics from "hoist-non-react-statics";
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
- var routerPlugin = function(param) {
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 originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
15
- var isBrow = isBrowser();
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
- registerHook: {
16
+ registryHooks: {
28
17
  modifyRoutes: modifyRoutesHook
29
18
  },
30
19
  setup: function(api) {
31
- return {
32
- init: function init(param2, next) {
33
- var context = param2.context;
34
- context.router = {
35
- useRouteMatch,
36
- useLocation
37
- };
38
- Object.defineProperty(context, "routes", {
39
- get: function get() {
40
- return routes;
41
- }
42
- });
43
- return next({
44
- context
45
- });
46
- },
47
- hoc: function(param2, next) {
48
- var App = param2.App;
49
- var getRouteApp = function() {
50
- if (isBrow) {
51
- var _window__SERVER_DATA;
52
- var baseUrl = ((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname);
53
- historyOptions.basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
54
- var history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
55
- return function(props) {
56
- var runner = api.useHookRunners();
57
- routes = runner.modifyRoutes(originRoutes);
58
- routesConfig && (routesConfig.routes = routes);
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 ssrContext = runtimeContext.ssrContext;
72
- var _$location = getLocation(ssrContext);
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;
76
- var basename = baseUrl2 === "/" ? urlJoin(baseUrl2, historyOptions.basename) : baseUrl2;
77
- var runner = api.useHookRunners();
78
- var routes2 = runner.modifyRoutes(originRoutes);
79
- routesConfig && (routesConfig.routes = routes2);
80
- return /* @__PURE__ */ _jsx(StaticRouter, {
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
- })) : /* @__PURE__ */ _jsx(App, _object_spread_props(_object_spread({}, props), {
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
- if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
97
- return next({
98
- App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
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
- return next({
102
- App: RouteApp
103
- });
104
- }
105
- };
85
+ };
86
+ };
87
+ return getRouteApp();
88
+ });
106
89
  }
107
90
  };
108
91
  };
@@ -1,95 +1,51 @@
1
- import { getEntryOptions, createRuntimeExportsUtils, isRouterV5 as isV5 } from "@modern-js/utils";
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
- return {
15
- config() {
16
- const appContext = api.useAppContext();
17
- pluginsExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "plugins");
18
- routerExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "router");
19
- return {
20
- source: {
21
- alias: {
22
- "@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
23
- "@modern-js/runtime/router-v5": routerExportsUtils.getPath()
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
- return {
60
- entrypoint,
61
- imports
62
- };
63
- },
64
- modifyEntryRuntimePlugins({ entrypoint, plugins }) {
65
- const { entryName, fileSystemRoutes } = entrypoint;
66
- const { serverRoutes } = api.useAppContext();
67
- const runtimeConfig = runtimeConfigMap.get(entryName);
68
- const userConfig = api.useResolvedConfigContext();
69
- if (isV5(userConfig)) {
70
- const serverBase = serverRoutes.filter((route) => route.entryName === entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
71
- plugins.push({
72
- name: PLUGIN_IDENTIFIER,
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,5 +1,5 @@
1
- import { createWaterfall } from "@modern-js/plugin";
2
- const modifyRoutesHook = createWaterfall();
1
+ import { createSyncHook } from "@modern-js/plugin-v2";
2
+ const modifyRoutesHook = createSyncHook();
3
3
  export {
4
4
  modifyRoutesHook
5
5
  };
@@ -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 { useContext } from "react";
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 { Router, StaticRouter, useRouteMatch, useLocation } from "react-router-dom";
5
- import hoistNonReactStatics from "hoist-non-react-statics";
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
- const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} }) => {
11
- const originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
12
- const isBrow = isBrowser();
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
- registerHook: {
14
+ registryHooks: {
21
15
  modifyRoutes: modifyRoutesHook
22
16
  },
23
17
  setup: (api) => {
24
- return {
25
- init({ context }, next) {
26
- context.router = {
27
- useRouteMatch,
28
- useLocation
29
- };
30
- Object.defineProperty(context, "routes", {
31
- get() {
32
- return routes;
33
- }
34
- });
35
- return next({
36
- context
37
- });
38
- },
39
- hoc: ({ App }, next) => {
40
- const getRouteApp = () => {
41
- if (isBrow) {
42
- var _window__SERVER_DATA;
43
- const baseUrl = ((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname);
44
- historyOptions.basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
45
- const history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
46
- return (props) => {
47
- const runner = api.useHookRunners();
48
- routes = runner.modifyRoutes(originRoutes);
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 { ssrContext } = runtimeContext;
65
- const location1 = getLocation(ssrContext);
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;
69
- const basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
70
- const runner = api.useHookRunners();
71
- const routes2 = runner.modifyRoutes(originRoutes);
72
- routesConfig && (routesConfig.routes = routes2);
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
- children: renderRoutes(routesConfig, props)
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
- if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
92
- return next({
93
- App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
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
- return next({
97
- App: RouteApp
98
- });
99
- }
100
- };
85
+ };
86
+ };
87
+ return getRouteApp();
88
+ });
101
89
  }
102
90
  };
103
91
  };
@@ -1,4 +1,4 @@
1
- import type { AppTools, CliPlugin } from '@modern-js/app-tools';
1
+ import type { AppTools, CliPluginFuture } from '@modern-js/app-tools';
2
2
  import './types';
3
- export declare const routerPlugin: () => CliPlugin<AppTools>;
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
- interface RuntimeUserConfig {
4
- router?: RouterConfig | boolean;
5
- }
6
- }
3
+ interface RuntimeUserConfig {
4
+ router?: RouterConfig | boolean;
5
+ }
6
+ }
@@ -1,2 +1,2 @@
1
1
  export { default } from './runtime';
2
- export * from './runtime';
2
+ export * from './runtime';
@@ -1,2 +1,2 @@
1
- /// <reference types="react" />
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
- declare const modifyRoutesHook: import("@modern-js/plugin").Waterfall<RouteProps<string, {
3
- [x: string]: string | undefined;
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
- import type { SingleRouteConfig, HistoryConfig, RouterConfig } from './plugin';
3
- export type { SingleRouteConfig, HistoryConfig, RouterConfig };
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';