@modern-js/plugin-router-v5 2.63.6 → 2.64.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,8 +21,8 @@ __export(hooks_exports, {
21
21
  modifyRoutesHook: () => modifyRoutesHook
22
22
  });
23
23
  module.exports = __toCommonJS(hooks_exports);
24
- var import_plugin = require("@modern-js/plugin");
25
- const modifyRoutesHook = (0, import_plugin.createWaterfall)();
24
+ var import_plugin_v2 = require("@modern-js/plugin-v2");
25
+ const modifyRoutesHook = (0, import_plugin_v2.createSyncHook)();
26
26
  // Annotate the CommonJS export names for ESM import in node:
27
27
  0 && (module.exports = {
28
28
  modifyRoutesHook
@@ -34,71 +34,46 @@ let routes = [];
34
34
  const routerPlugin = (userConfig = {}) => {
35
35
  return {
36
36
  name: "@modern-js/plugin-router",
37
- registerHook: {
37
+ registryHooks: {
38
38
  modifyRoutes: import_hooks.modifyRoutesHook
39
39
  },
40
40
  setup: (api) => {
41
- return {
42
- beforeRender(context) {
43
- context.router = {
44
- useRouteMatch: import_react_router_dom.useRouteMatch,
45
- useLocation: import_react_router_dom.useLocation,
46
- useHistory: import_react_router_dom.useHistory
47
- };
48
- Object.defineProperty(context, "routes", {
49
- get() {
50
- return routes;
51
- }
52
- });
53
- },
54
- wrapRoot: (App) => {
55
- const pluginConfig = api.useRuntimeConfigContext();
56
- const { serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} } = (0, import_merge.merge)(pluginConfig.router || {}, userConfig);
57
- const finalRouteConfig = {
58
- routes: (0, import_context.getGlobalRoutes)(),
59
- globalApp: (0, import_context.getGlobalLayoutApp)(),
60
- ...routesConfig
61
- };
62
- const originRoutes = finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes;
63
- const isBrow = (0, import_runtime.isBrowser)();
64
- const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
65
- const getRouteApp = () => {
66
- if (isBrow) {
67
- return (props) => {
68
- const runtimeContext = (0, import_react.useContext)(import_runtime.RuntimeReactContext);
69
- const baseUrl = select(location.pathname).replace(/^\/*/, "/");
70
- const basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, runtimeContext._internalRouterBaseName || historyOptions.basename) : baseUrl;
71
- historyOptions.basename = basename;
72
- const history = customHistory || (supportHtml5History ? (0, import_history.createBrowserHistory)(historyOptions) : (0, import_history.createHashHistory)(historyOptions));
73
- const runner = api.useHookRunners();
74
- routes = runner.modifyRoutes(originRoutes);
75
- finalRouteConfig && (finalRouteConfig.routes = routes);
76
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Router, {
77
- history,
78
- children: createRoutes ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
79
- Component: createRoutes()
80
- }) : App && !(finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
81
- ...props
82
- }) : (0, import_utils.renderRoutes)(finalRouteConfig, props)
83
- });
84
- };
85
- }
41
+ api.onBeforeRender((context) => {
42
+ context.router = {
43
+ useRouteMatch: import_react_router_dom.useRouteMatch,
44
+ useLocation: import_react_router_dom.useLocation,
45
+ useHistory: import_react_router_dom.useHistory
46
+ };
47
+ Object.defineProperty(context, "routes", {
48
+ get() {
49
+ return routes;
50
+ }
51
+ });
52
+ });
53
+ api.wrapRoot((App) => {
54
+ const pluginConfig = api.getRuntimeConfig();
55
+ const { serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} } = (0, import_merge.merge)(pluginConfig.router || {}, userConfig);
56
+ const finalRouteConfig = {
57
+ routes: (0, import_context.getGlobalRoutes)(),
58
+ globalApp: (0, import_context.getGlobalLayoutApp)(),
59
+ ...routesConfig
60
+ };
61
+ const originRoutes = finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes;
62
+ const isBrow = (0, import_runtime.isBrowser)();
63
+ const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
64
+ const getRouteApp = () => {
65
+ if (isBrow) {
86
66
  return (props) => {
87
- var _request_baseUrl;
88
67
  const runtimeContext = (0, import_react.useContext)(import_runtime.RuntimeReactContext);
89
- const { ssrContext } = runtimeContext;
90
- const location1 = (0, import_utils.getLocation)(ssrContext);
91
- const routerContext = (ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.redirection) || {};
92
- const request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
93
- const baseUrl = request === null || request === void 0 ? void 0 : (_request_baseUrl = request.baseUrl) === null || _request_baseUrl === void 0 ? void 0 : _request_baseUrl.replace(/^\/*/, "/");
68
+ const baseUrl = select(location.pathname).replace(/^\/*/, "/");
94
69
  const basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, runtimeContext._internalRouterBaseName || historyOptions.basename) : baseUrl;
95
- const runner = api.useHookRunners();
96
- const routes2 = runner.modifyRoutes(originRoutes);
97
- finalRouteConfig && (finalRouteConfig.routes = routes2);
98
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.StaticRouter, {
99
- basename: basename === "/" ? "" : basename,
100
- location: location1,
101
- context: routerContext,
70
+ historyOptions.basename = basename;
71
+ const history = customHistory || (supportHtml5History ? (0, import_history.createBrowserHistory)(historyOptions) : (0, import_history.createHashHistory)(historyOptions));
72
+ const hooks = api.getHooks();
73
+ routes = hooks.modifyRoutes.call(originRoutes);
74
+ finalRouteConfig && (finalRouteConfig.routes = routes);
75
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Router, {
76
+ history,
102
77
  children: createRoutes ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
103
78
  Component: createRoutes()
104
79
  }) : App && !(finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
@@ -106,10 +81,33 @@ const routerPlugin = (userConfig = {}) => {
106
81
  }) : (0, import_utils.renderRoutes)(finalRouteConfig, props)
107
82
  });
108
83
  };
84
+ }
85
+ return (props) => {
86
+ var _request_baseUrl;
87
+ const runtimeContext = (0, import_react.useContext)(import_runtime.RuntimeReactContext);
88
+ const { ssrContext } = runtimeContext;
89
+ const location1 = (0, import_utils.getLocation)(ssrContext);
90
+ const routerContext = (ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.redirection) || {};
91
+ const request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
92
+ const baseUrl = request === null || request === void 0 ? void 0 : (_request_baseUrl = request.baseUrl) === null || _request_baseUrl === void 0 ? void 0 : _request_baseUrl.replace(/^\/*/, "/");
93
+ const basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, runtimeContext._internalRouterBaseName || historyOptions.basename) : baseUrl;
94
+ const hooks = api.getHooks();
95
+ const routes2 = hooks.modifyRoutes.call(originRoutes);
96
+ finalRouteConfig && (finalRouteConfig.routes = routes2);
97
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.StaticRouter, {
98
+ basename: basename === "/" ? "" : basename,
99
+ location: location1,
100
+ context: routerContext,
101
+ children: createRoutes ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
102
+ Component: createRoutes()
103
+ }) : App && !(finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
104
+ ...props
105
+ }) : (0, import_utils.renderRoutes)(finalRouteConfig, props)
106
+ });
109
107
  };
110
- return getRouteApp();
111
- }
112
- };
108
+ };
109
+ return getRouteApp();
110
+ });
113
111
  }
114
112
  };
115
113
  };
@@ -1,5 +1,5 @@
1
- import { createWaterfall } from "@modern-js/plugin";
2
- var modifyRoutesHook = createWaterfall();
1
+ import { createSyncHook } from "@modern-js/plugin-v2";
2
+ var modifyRoutesHook = createSyncHook();
3
3
  export {
4
4
  modifyRoutesHook
5
5
  };
@@ -13,81 +13,79 @@ var routerPlugin = function() {
13
13
  var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
14
14
  return {
15
15
  name: "@modern-js/plugin-router",
16
- registerHook: {
16
+ registryHooks: {
17
17
  modifyRoutes: modifyRoutesHook
18
18
  },
19
19
  setup: function(api) {
20
- return {
21
- beforeRender: function beforeRender(context) {
22
- context.router = {
23
- useRouteMatch,
24
- useLocation,
25
- useHistory
26
- };
27
- Object.defineProperty(context, "routes", {
28
- get: function get() {
29
- return routes;
30
- }
31
- });
32
- },
33
- wrapRoot: function(App) {
34
- var pluginConfig = api.useRuntimeConfigContext();
35
- 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;
36
- var finalRouteConfig = _object_spread({
37
- routes: getGlobalRoutes(),
38
- globalApp: getGlobalLayoutApp()
39
- }, routesConfig);
40
- var originRoutes = finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes;
41
- var isBrow = isBrowser();
42
- var select = function(pathname) {
43
- return serverBase.find(function(baseUrl) {
44
- return pathname.search(baseUrl) === 0;
45
- }) || "/";
46
- };
47
- var getRouteApp = function() {
48
- if (isBrow) {
49
- return function(props) {
50
- var runtimeContext = useContext(RuntimeReactContext);
51
- var baseUrl = select(location.pathname).replace(/^\/*/, "/");
52
- var basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || historyOptions.basename) : baseUrl;
53
- historyOptions.basename = basename;
54
- var history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
55
- var runner = api.useHookRunners();
56
- routes = runner.modifyRoutes(originRoutes);
57
- finalRouteConfig && (finalRouteConfig.routes = routes);
58
- return /* @__PURE__ */ _jsx(Router, {
59
- history,
60
- children: createRoutes ? /* @__PURE__ */ _jsx(App, {
61
- Component: createRoutes()
62
- }) : App && !(finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes) ? /* @__PURE__ */ _jsx(App, _object_spread({}, props)) : renderRoutes(finalRouteConfig, props)
63
- });
64
- };
65
- }
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) {
66
48
  return function(props) {
67
- var _request_baseUrl;
68
49
  var runtimeContext = useContext(RuntimeReactContext);
69
- var ssrContext = runtimeContext.ssrContext;
70
- var location1 = getLocation(ssrContext);
71
- var routerContext = (ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.redirection) || {};
72
- var request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
73
- var baseUrl = request === null || request === void 0 ? void 0 : (_request_baseUrl = request.baseUrl) === null || _request_baseUrl === void 0 ? void 0 : _request_baseUrl.replace(/^\/*/, "/");
50
+ var baseUrl = select(location.pathname).replace(/^\/*/, "/");
74
51
  var basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || historyOptions.basename) : baseUrl;
75
- var runner = api.useHookRunners();
76
- var routes2 = runner.modifyRoutes(originRoutes);
77
- finalRouteConfig && (finalRouteConfig.routes = routes2);
78
- return /* @__PURE__ */ _jsx(StaticRouter, {
79
- basename: basename === "/" ? "" : basename,
80
- location: location1,
81
- context: routerContext,
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,
82
59
  children: createRoutes ? /* @__PURE__ */ _jsx(App, {
83
60
  Component: createRoutes()
84
61
  }) : App && !(finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes) ? /* @__PURE__ */ _jsx(App, _object_spread({}, props)) : renderRoutes(finalRouteConfig, props)
85
62
  });
86
63
  };
64
+ }
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, {
82
+ Component: createRoutes()
83
+ }) : App && !(finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes) ? /* @__PURE__ */ _jsx(App, _object_spread({}, props)) : renderRoutes(finalRouteConfig, props)
84
+ });
87
85
  };
88
- return getRouteApp();
89
- }
90
- };
86
+ };
87
+ return getRouteApp();
88
+ });
91
89
  }
92
90
  };
93
91
  };
@@ -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
  };
@@ -11,71 +11,46 @@ let routes = [];
11
11
  const routerPlugin = (userConfig = {}) => {
12
12
  return {
13
13
  name: "@modern-js/plugin-router",
14
- registerHook: {
14
+ registryHooks: {
15
15
  modifyRoutes: modifyRoutesHook
16
16
  },
17
17
  setup: (api) => {
18
- return {
19
- beforeRender(context) {
20
- context.router = {
21
- useRouteMatch,
22
- useLocation,
23
- useHistory
24
- };
25
- Object.defineProperty(context, "routes", {
26
- get() {
27
- return routes;
28
- }
29
- });
30
- },
31
- wrapRoot: (App) => {
32
- const pluginConfig = api.useRuntimeConfigContext();
33
- const { serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} } = merge(pluginConfig.router || {}, userConfig);
34
- const finalRouteConfig = {
35
- routes: getGlobalRoutes(),
36
- globalApp: getGlobalLayoutApp(),
37
- ...routesConfig
38
- };
39
- const originRoutes = finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes;
40
- const isBrow = isBrowser();
41
- const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
42
- const getRouteApp = () => {
43
- if (isBrow) {
44
- return (props) => {
45
- const runtimeContext = useContext(RuntimeReactContext);
46
- const baseUrl = select(location.pathname).replace(/^\/*/, "/");
47
- const basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || historyOptions.basename) : baseUrl;
48
- historyOptions.basename = basename;
49
- const history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
50
- const runner = api.useHookRunners();
51
- routes = runner.modifyRoutes(originRoutes);
52
- finalRouteConfig && (finalRouteConfig.routes = routes);
53
- return /* @__PURE__ */ _jsx(Router, {
54
- history,
55
- children: createRoutes ? /* @__PURE__ */ _jsx(App, {
56
- Component: createRoutes()
57
- }) : App && !(finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes) ? /* @__PURE__ */ _jsx(App, {
58
- ...props
59
- }) : renderRoutes(finalRouteConfig, props)
60
- });
61
- };
62
- }
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) {
63
43
  return (props) => {
64
- var _request_baseUrl;
65
44
  const runtimeContext = useContext(RuntimeReactContext);
66
- const { ssrContext } = runtimeContext;
67
- const location1 = getLocation(ssrContext);
68
- const routerContext = (ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.redirection) || {};
69
- const request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
70
- const baseUrl = request === null || request === void 0 ? void 0 : (_request_baseUrl = request.baseUrl) === null || _request_baseUrl === void 0 ? void 0 : _request_baseUrl.replace(/^\/*/, "/");
45
+ const baseUrl = select(location.pathname).replace(/^\/*/, "/");
71
46
  const basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || historyOptions.basename) : baseUrl;
72
- const runner = api.useHookRunners();
73
- const routes2 = runner.modifyRoutes(originRoutes);
74
- finalRouteConfig && (finalRouteConfig.routes = routes2);
75
- return /* @__PURE__ */ _jsx(StaticRouter, {
76
- basename: basename === "/" ? "" : basename,
77
- location: location1,
78
- context: routerContext,
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,
79
54
  children: createRoutes ? /* @__PURE__ */ _jsx(App, {
80
55
  Component: createRoutes()
81
56
  }) : App && !(finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes) ? /* @__PURE__ */ _jsx(App, {
@@ -83,10 +58,33 @@ const routerPlugin = (userConfig = {}) => {
83
58
  }) : renderRoutes(finalRouteConfig, props)
84
59
  });
85
60
  };
61
+ }
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
+ }) : App && !(finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes) ? /* @__PURE__ */ _jsx(App, {
81
+ ...props
82
+ }) : renderRoutes(finalRouteConfig, props)
83
+ });
86
84
  };
87
- return getRouteApp();
88
- }
89
- };
85
+ };
86
+ return getRouteApp();
87
+ });
90
88
  }
91
89
  };
92
90
  };
@@ -1,5 +1,4 @@
1
1
  import type { RouteProps } from 'react-router-dom';
2
- declare const modifyRoutesHook: import("@modern-js/plugin").Waterfall<RouteProps<string, {
3
- [x: string]: string | undefined;
4
- }>[]>;
2
+ import type { SingleRouteConfig } from './plugin';
3
+ declare const modifyRoutesHook: import("@modern-js/plugin-v2/src/types/hooks").SyncHook<(routes: RouteProps[]) => SingleRouteConfig[]>;
5
4
  export { modifyRoutesHook };
@@ -1,5 +1,5 @@
1
1
  import { routerPlugin } from './plugin';
2
- export type { SingleRouteConfig, HistoryConfig, RouterConfig } from './plugin';
2
+ export type { SingleRouteConfig, HistoryConfig, RouterConfig, RouterExtendsHooks, } from './plugin';
3
3
  export { routerPlugin } from './plugin';
4
4
  export default routerPlugin;
5
5
  export * from 'react-router-dom';
@@ -1,7 +1,11 @@
1
- import type { Plugin } from '@modern-js/runtime';
1
+ import type { RuntimePluginFuture } from '@modern-js/runtime';
2
2
  import { type BrowserHistoryBuildOptions, type HashHistoryBuildOptions, type History } from 'history';
3
3
  import type React from 'react';
4
4
  import { type RouteProps } from 'react-router-dom';
5
+ import { modifyRoutesHook } from './hooks';
6
+ export type RouterExtendsHooks = {
7
+ modifyRoutes: typeof modifyRoutesHook;
8
+ };
5
9
  export type SingleRouteConfig = RouteProps & {
6
10
  redirect?: string;
7
11
  routes?: SingleRouteConfig[];
@@ -32,4 +36,6 @@ export type RouterConfig = Partial<HistoryConfig> & {
32
36
  history?: History;
33
37
  serverBase?: string[];
34
38
  };
35
- export declare const routerPlugin: (userConfig?: RouterConfig) => Plugin;
39
+ export declare const routerPlugin: (userConfig?: RouterConfig) => RuntimePluginFuture<{
40
+ extendHooks: RouterExtendsHooks;
41
+ }>;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.63.6",
18
+ "version": "2.64.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,16 +59,16 @@
59
59
  "@types/react-router-dom": "^5.1.8",
60
60
  "history": "^4.7.9",
61
61
  "react-router-dom": "^5.3.4",
62
- "@modern-js/plugin": "2.63.6",
63
- "@modern-js/plugin-v2": "2.63.6",
64
- "@modern-js/runtime-utils": "2.63.6",
65
- "@modern-js/types": "2.63.6",
66
- "@modern-js/utils": "2.63.6"
62
+ "@modern-js/plugin": "2.64.0",
63
+ "@modern-js/plugin-v2": "2.64.0",
64
+ "@modern-js/runtime-utils": "2.64.0",
65
+ "@modern-js/types": "2.64.0",
66
+ "@modern-js/utils": "2.64.0"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "react": ">=17",
70
70
  "react-dom": ">=17",
71
- "@modern-js/runtime": "^2.63.6"
71
+ "@modern-js/runtime": "^2.64.0"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@testing-library/react": "^13.4.0",
@@ -80,11 +80,11 @@
80
80
  "react-dom": "^18.3.1",
81
81
  "ts-jest": "^29.1.0",
82
82
  "typescript": "^5",
83
- "@modern-js/app-tools": "2.63.6",
84
- "@modern-js/core": "2.63.6",
85
- "@modern-js/runtime": "2.63.6",
86
- "@scripts/build": "2.63.6",
87
- "@scripts/jest-config": "2.63.6"
83
+ "@modern-js/app-tools": "2.64.0",
84
+ "@modern-js/core": "2.64.0",
85
+ "@modern-js/runtime": "2.64.0",
86
+ "@scripts/build": "2.64.0",
87
+ "@scripts/jest-config": "2.64.0"
88
88
  },
89
89
  "sideEffects": false,
90
90
  "publishConfig": {