@xfe-repo/web-router 1.0.5 → 1.1.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/index.d.mts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { History } from 'history';
2
2
  import { LoadableComponent, loadableReady } from '@loadable/component';
3
3
  import { ParsedQuery } from 'query-string';
4
- import React, { ReactElement, ComponentType } from 'react';
4
+ import React, { ReactElement, PropsWithChildren, ComponentType } from 'react';
5
5
  import { RegisterComponentStatic } from '@xfe-repo/web-register';
6
6
  export * from 'react-router-dom';
7
+ import * as react_jsx_runtime from 'react/jsx-runtime';
7
8
 
8
9
  type PageComponent = LoadableComponent<any> & RegisterComponentStatic;
9
10
  type RouteConfig = {
@@ -17,24 +18,22 @@ type GetRoutesConfig = {
17
18
  };
18
19
  declare const getRoutes: (config: GetRoutesConfig) => RouteConfig[];
19
20
 
20
- type RouterProps = {
21
+ type RouterProps = PropsWithChildren<{
21
22
  navigator: NavigatorType;
22
23
  routes: RouteConfig[];
23
24
  basename?: string;
24
- children: ReactElement;
25
25
  NotFoundPageComponent?: ComponentType;
26
- };
27
- declare const Router: React.MemoExoticComponent<(props: RouterProps) => JSX.Element>;
26
+ }>;
27
+ declare const Router: React.MemoExoticComponent<(props: RouterProps) => react_jsx_runtime.JSX.Element>;
28
28
 
29
- type LinkProps = {
29
+ type LinkProps = PropsWithChildren<{
30
30
  to: string;
31
- children?: ReactElement | string | ReactElement[];
32
31
  reLaunch?: boolean;
33
32
  replace?: boolean;
34
33
  preload?: boolean;
35
34
  className?: string;
36
- };
37
- declare const Link: (props: LinkProps) => JSX.Element;
35
+ }>;
36
+ declare const Link: React.MemoExoticComponent<(props: LinkProps) => react_jsx_runtime.JSX.Element>;
38
37
 
39
38
  type NavigatorStack = {
40
39
  pathname: string;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { History } from 'history';
2
2
  import { LoadableComponent, loadableReady } from '@loadable/component';
3
3
  import { ParsedQuery } from 'query-string';
4
- import React, { ReactElement, ComponentType } from 'react';
4
+ import React, { ReactElement, PropsWithChildren, ComponentType } from 'react';
5
5
  import { RegisterComponentStatic } from '@xfe-repo/web-register';
6
6
  export * from 'react-router-dom';
7
+ import * as react_jsx_runtime from 'react/jsx-runtime';
7
8
 
8
9
  type PageComponent = LoadableComponent<any> & RegisterComponentStatic;
9
10
  type RouteConfig = {
@@ -17,24 +18,22 @@ type GetRoutesConfig = {
17
18
  };
18
19
  declare const getRoutes: (config: GetRoutesConfig) => RouteConfig[];
19
20
 
20
- type RouterProps = {
21
+ type RouterProps = PropsWithChildren<{
21
22
  navigator: NavigatorType;
22
23
  routes: RouteConfig[];
23
24
  basename?: string;
24
- children: ReactElement;
25
25
  NotFoundPageComponent?: ComponentType;
26
- };
27
- declare const Router: React.MemoExoticComponent<(props: RouterProps) => JSX.Element>;
26
+ }>;
27
+ declare const Router: React.MemoExoticComponent<(props: RouterProps) => react_jsx_runtime.JSX.Element>;
28
28
 
29
- type LinkProps = {
29
+ type LinkProps = PropsWithChildren<{
30
30
  to: string;
31
- children?: ReactElement | string | ReactElement[];
32
31
  reLaunch?: boolean;
33
32
  replace?: boolean;
34
33
  preload?: boolean;
35
34
  className?: string;
36
- };
37
- declare const Link: (props: LinkProps) => JSX.Element;
35
+ }>;
36
+ declare const Link: React.MemoExoticComponent<(props: LinkProps) => react_jsx_runtime.JSX.Element>;
38
37
 
39
38
  type NavigatorStack = {
40
39
  pathname: string;
package/dist/index.js CHANGED
@@ -355,7 +355,7 @@ var Router = (0, import_react.memo)(function(props) {
355
355
  var import_react2 = require("react");
356
356
  var import_react_router_dom2 = require("react-router-dom");
357
357
  var import_jsx_runtime2 = require("react/jsx-runtime");
358
- var Link = function(props) {
358
+ var Link = (0, import_react2.memo)(function(props) {
359
359
  var to = props.to, children = props.children, reLaunch = props.reLaunch, preload = props.preload, replace = props.replace, className = props.className;
360
360
  var _navigator2 = (0, import_react2.useMemo)(function() {
361
361
  return getClientNavigator();
@@ -415,7 +415,7 @@ var Link = function(props) {
415
415
  });
416
416
  }
417
417
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_router_dom2.Link, _object_spread({}, props));
418
- };
418
+ });
419
419
  // src/index.ts
420
420
  var _navigator;
421
421
  function createNavigator(options) {
package/dist/index.mjs CHANGED
@@ -1,146 +1,453 @@
1
1
  // src/index.ts
2
+ function _array_like_to_array(arr, len) {
3
+ if (len == null || len > arr.length) len = arr.length;
4
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5
+ return arr2;
6
+ }
7
+ function _array_with_holes(arr) {
8
+ if (Array.isArray(arr)) return arr;
9
+ }
10
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
11
+ try {
12
+ var info = gen[key](arg);
13
+ var value = info.value;
14
+ } catch (error) {
15
+ reject(error);
16
+ return;
17
+ }
18
+ if (info.done) {
19
+ resolve(value);
20
+ } else {
21
+ Promise.resolve(value).then(_next, _throw);
22
+ }
23
+ }
24
+ function _async_to_generator(fn) {
25
+ return function() {
26
+ var self = this, args = arguments;
27
+ return new Promise(function(resolve, reject) {
28
+ var gen = fn.apply(self, args);
29
+ function _next(value) {
30
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
31
+ }
32
+ function _throw(err) {
33
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
34
+ }
35
+ _next(undefined);
36
+ });
37
+ };
38
+ }
39
+ function _define_property(obj, key, value) {
40
+ if (key in obj) {
41
+ Object.defineProperty(obj, key, {
42
+ value: value,
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true
46
+ });
47
+ } else {
48
+ obj[key] = value;
49
+ }
50
+ return obj;
51
+ }
52
+ function _iterable_to_array_limit(arr, i) {
53
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
54
+ if (_i == null) return;
55
+ var _arr = [];
56
+ var _n = true;
57
+ var _d = false;
58
+ var _s, _e;
59
+ try {
60
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
61
+ _arr.push(_s.value);
62
+ if (i && _arr.length === i) break;
63
+ }
64
+ } catch (err) {
65
+ _d = true;
66
+ _e = err;
67
+ } finally{
68
+ try {
69
+ if (!_n && _i["return"] != null) _i["return"]();
70
+ } finally{
71
+ if (_d) throw _e;
72
+ }
73
+ }
74
+ return _arr;
75
+ }
76
+ function _non_iterable_rest() {
77
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
78
+ }
79
+ function _object_spread(target) {
80
+ for(var i = 1; i < arguments.length; i++){
81
+ var source = arguments[i] != null ? arguments[i] : {};
82
+ var ownKeys = Object.keys(source);
83
+ if (typeof Object.getOwnPropertySymbols === "function") {
84
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
85
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
86
+ }));
87
+ }
88
+ ownKeys.forEach(function(key) {
89
+ _define_property(target, key, source[key]);
90
+ });
91
+ }
92
+ return target;
93
+ }
94
+ function _sliced_to_array(arr, i) {
95
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
96
+ }
97
+ function _unsupported_iterable_to_array(o, minLen) {
98
+ if (!o) return;
99
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
100
+ var n = Object.prototype.toString.call(o).slice(8, -1);
101
+ if (n === "Object" && o.constructor) n = o.constructor.name;
102
+ if (n === "Map" || n === "Set") return Array.from(n);
103
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
104
+ }
105
+ function _ts_generator(thisArg, body) {
106
+ var f, y, t, g, _ = {
107
+ label: 0,
108
+ sent: function() {
109
+ if (t[0] & 1) throw t[1];
110
+ return t[1];
111
+ },
112
+ trys: [],
113
+ ops: []
114
+ };
115
+ return g = {
116
+ next: verb(0),
117
+ "throw": verb(1),
118
+ "return": verb(2)
119
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
120
+ return this;
121
+ }), g;
122
+ function verb(n) {
123
+ return function(v) {
124
+ return step([
125
+ n,
126
+ v
127
+ ]);
128
+ };
129
+ }
130
+ function step(op) {
131
+ if (f) throw new TypeError("Generator is already executing.");
132
+ while(_)try {
133
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
134
+ if (y = 0, t) op = [
135
+ op[0] & 2,
136
+ t.value
137
+ ];
138
+ switch(op[0]){
139
+ case 0:
140
+ case 1:
141
+ t = op;
142
+ break;
143
+ case 4:
144
+ _.label++;
145
+ return {
146
+ value: op[1],
147
+ done: false
148
+ };
149
+ case 5:
150
+ _.label++;
151
+ y = op[1];
152
+ op = [
153
+ 0
154
+ ];
155
+ continue;
156
+ case 7:
157
+ op = _.ops.pop();
158
+ _.trys.pop();
159
+ continue;
160
+ default:
161
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
162
+ _ = 0;
163
+ continue;
164
+ }
165
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
166
+ _.label = op[1];
167
+ break;
168
+ }
169
+ if (op[0] === 6 && _.label < t[1]) {
170
+ _.label = t[1];
171
+ t = op;
172
+ break;
173
+ }
174
+ if (t && _.label < t[2]) {
175
+ _.label = t[2];
176
+ _.ops.push(op);
177
+ break;
178
+ }
179
+ if (t[2]) _.ops.pop();
180
+ _.trys.pop();
181
+ continue;
182
+ }
183
+ op = body.call(thisArg, _);
184
+ } catch (e) {
185
+ op = [
186
+ 6,
187
+ e
188
+ ];
189
+ y = 0;
190
+ } finally{
191
+ f = t = 0;
192
+ }
193
+ if (op[0] & 5) throw op[1];
194
+ return {
195
+ value: op[0] ? op[1] : void 0,
196
+ done: true
197
+ };
198
+ }
199
+ }
2
200
  import { createHashHistory, createBrowserHistory, createMemoryHistory } from "history";
3
201
  import { loadableReady } from "@loadable/component";
4
202
  import { matchRoutes } from "react-router-dom";
5
203
  import queryString from "query-string";
6
204
  export * from "react-router-dom";
7
-
8
205
  // src/routes.ts
9
206
  import loadable from "@loadable/component";
10
- var getRoutes = (config) => {
11
- const { pagesIndexPath, getPageComponents, fallback } = config;
12
- const routes = [];
13
- pagesIndexPath.forEach((pageIndexPath) => {
14
- if (pageIndexPath.startsWith("./"))
15
- return;
16
- const regExpResult = pageIndexPath.match(/(?<=pages\/).*(?=\/index.(?:tsx|js))/);
17
- const pageRelativePath = regExpResult ? regExpResult[0].toLowerCase() : "";
18
- const pageComponent = loadable(() => getPageComponents(pageRelativePath), { fallback });
19
- let routerPath = `/${pageRelativePath}`;
20
- if (routerPath === "/home" || routerPath === "/index")
21
- routerPath = "/";
22
- const config2 = {
23
- path: routerPath,
24
- Component: pageComponent
25
- };
26
- routes.push(config2);
27
- });
28
- return routes;
207
+ var getRoutes = function(config) {
208
+ var pagesIndexPath = config.pagesIndexPath, getPageComponents = config.getPageComponents, fallback = config.fallback;
209
+ var routes = [];
210
+ pagesIndexPath.forEach(function(pageIndexPath) {
211
+ if (pageIndexPath.startsWith("./")) return;
212
+ var regExpResult = pageIndexPath.match(RegExp("(?<=pages\\/).*(?=\\/index.(?:tsx|js))"));
213
+ var pageRelativePath = regExpResult ? regExpResult[0].toLowerCase() : "";
214
+ var pageComponent = loadable(function() {
215
+ return getPageComponents(pageRelativePath);
216
+ }, {
217
+ fallback: fallback
218
+ });
219
+ var routerPath = "/".concat(pageRelativePath);
220
+ if (routerPath === "/home" || routerPath === "/index") routerPath = "/";
221
+ var config2 = {
222
+ path: routerPath,
223
+ Component: pageComponent
224
+ };
225
+ routes.push(config2);
226
+ });
227
+ return routes;
29
228
  };
30
-
31
229
  // src/Router.tsx
32
230
  import { memo, useState, useEffect } from "react";
33
231
  import { Router as OriginalRouter, Routes, Route } from "react-router-dom";
34
232
  import { jsx, jsxs } from "react/jsx-runtime";
35
- var Router = memo((props) => {
36
- const { navigator, routes, basename = "/", children, NotFoundPageComponent } = props;
37
- const [navigatorState, setNavigatorState] = useState({
38
- action: navigator.action,
39
- location: navigator.location
40
- });
41
- useEffect(() => navigator.listen(setNavigatorState), [navigator]);
42
- return /* @__PURE__ */ jsx(OriginalRouter, { navigator, navigationType: navigatorState.action, location: navigatorState.location, basename, children: /* @__PURE__ */ jsx(Routes, { children: /* @__PURE__ */ jsxs(Route, { path: "/", element: children, children: [
43
- routes.map(({ path, Component }) => /* @__PURE__ */ jsx(Route, { path, Component }, path)),
44
- NotFoundPageComponent && /* @__PURE__ */ jsx(Route, { path: "*", Component: NotFoundPageComponent })
45
- ] }) }) });
233
+ var Router = memo(function(props) {
234
+ var navigator = props.navigator, routes = props.routes, _props_basename = props.basename, basename = _props_basename === void 0 ? "/" : _props_basename, children = props.children, NotFoundPageComponent = props.NotFoundPageComponent;
235
+ var _useState = _sliced_to_array(useState({
236
+ action: navigator.action,
237
+ location: navigator.location
238
+ }), 2), navigatorState = _useState[0], setNavigatorState = _useState[1];
239
+ useEffect(function() {
240
+ return navigator.listen(setNavigatorState);
241
+ }, [
242
+ navigator
243
+ ]);
244
+ return /* @__PURE__ */ jsx(OriginalRouter, {
245
+ navigator: navigator,
246
+ navigationType: navigatorState.action,
247
+ location: navigatorState.location,
248
+ basename: basename,
249
+ children: /* @__PURE__ */ jsx(Routes, {
250
+ children: /* @__PURE__ */ jsxs(Route, {
251
+ path: "/",
252
+ element: children,
253
+ children: [
254
+ routes.map(function(param) {
255
+ var path = param.path, Component = param.Component;
256
+ return /* @__PURE__ */ jsx(Route, {
257
+ path: path,
258
+ Component: Component
259
+ }, path);
260
+ }),
261
+ NotFoundPageComponent && /* @__PURE__ */ jsx(Route, {
262
+ path: "*",
263
+ Component: NotFoundPageComponent
264
+ })
265
+ ]
266
+ })
267
+ })
268
+ });
46
269
  });
47
-
48
270
  // src/Link.tsx
49
- import { useMemo } from "react";
271
+ import { memo as memo2, useMemo } from "react";
50
272
  import { Link as OriginalLink } from "react-router-dom";
51
273
  import { jsx as jsx2 } from "react/jsx-runtime";
52
- var Link = (props) => {
53
- const { to, children, reLaunch, preload, replace, className } = props;
54
- const _navigator2 = useMemo(() => getClientNavigator(), []);
55
- if (/http(s)?:\/{2}/.test(to)) {
56
- const handleLink = (e) => {
57
- e.preventDefault();
58
- window.location.href = to;
59
- };
60
- return /* @__PURE__ */ jsx2("a", { href: to, onClick: handleLink, className, children });
61
- }
62
- if (reLaunch) {
63
- const handleLink = (e) => {
64
- e.preventDefault();
65
- _navigator2.reLaunch(to);
66
- };
67
- return /* @__PURE__ */ jsx2("a", { href: to, onClick: handleLink, className, children });
68
- }
69
- if (preload) {
70
- const handleLink = async (e) => {
71
- e.preventDefault();
72
- await _navigator2.preload(to, replace);
73
- };
74
- return /* @__PURE__ */ jsx2("a", { href: to, onClick: handleLink, className, children });
75
- }
76
- return /* @__PURE__ */ jsx2(OriginalLink, { ...props });
77
- };
78
-
274
+ var Link = memo2(function(props) {
275
+ var to = props.to, children = props.children, reLaunch = props.reLaunch, preload = props.preload, replace = props.replace, className = props.className;
276
+ var _navigator2 = useMemo(function() {
277
+ return getClientNavigator();
278
+ }, []);
279
+ if (/http(s)?:\/{2}/.test(to)) {
280
+ var handleLink = function(e) {
281
+ e.preventDefault();
282
+ window.location.href = to;
283
+ };
284
+ return /* @__PURE__ */ jsx2("a", {
285
+ href: to,
286
+ onClick: handleLink,
287
+ className: className,
288
+ children: children
289
+ });
290
+ }
291
+ if (reLaunch) {
292
+ var handleLink1 = function(e) {
293
+ e.preventDefault();
294
+ _navigator2.reLaunch(to);
295
+ };
296
+ return /* @__PURE__ */ jsx2("a", {
297
+ href: to,
298
+ onClick: handleLink1,
299
+ className: className,
300
+ children: children
301
+ });
302
+ }
303
+ if (preload) {
304
+ var handleLink2 = function() {
305
+ var _ref = _async_to_generator(function(e) {
306
+ return _ts_generator(this, function(_state) {
307
+ switch(_state.label){
308
+ case 0:
309
+ e.preventDefault();
310
+ return [
311
+ 4,
312
+ _navigator2.preload(to, replace)
313
+ ];
314
+ case 1:
315
+ _state.sent();
316
+ return [
317
+ 2
318
+ ];
319
+ }
320
+ });
321
+ });
322
+ return function handleLink2(e) {
323
+ return _ref.apply(this, arguments);
324
+ };
325
+ }();
326
+ return /* @__PURE__ */ jsx2("a", {
327
+ href: to,
328
+ onClick: handleLink2,
329
+ className: className,
330
+ children: children
331
+ });
332
+ }
333
+ return /* @__PURE__ */ jsx2(OriginalLink, _object_spread({}, props));
334
+ });
79
335
  // src/index.ts
80
336
  var _navigator;
81
337
  function createNavigator(options) {
82
- const { mode, initPathname = "/", routes } = options;
83
- let originHistory;
84
- if (mode === "static") {
85
- originHistory = createMemoryHistory({
86
- initialEntries: [initPathname]
87
- });
88
- } else if (mode === "browser") {
89
- originHistory = createBrowserHistory();
90
- } else {
91
- originHistory = createHashHistory();
92
- }
93
- _navigator = originHistory;
94
- const initialStack = [{ pathname: _navigator.location.pathname }];
95
- let stack = _navigator.stack = initialStack;
96
- _navigator.listen(({ location, action }) => {
97
- const { pathname } = location;
98
- if (action === "PUSH") {
99
- stack.push({ pathname });
100
- } else if (action === "REPLACE") {
101
- stack.pop();
102
- stack.push({ pathname });
103
- } else if (action === "POP") {
104
- stack.pop();
105
- }
106
- console.log("router", action, pathname, stack);
107
- });
108
- _navigator.reLaunch = (path, state) => {
109
- let shouldBlack = -stack.length + 1;
110
- if (shouldBlack < 0)
111
- _navigator.go(shouldBlack);
112
- if (stack[0]?.pathname === path)
113
- return;
114
- setTimeout(() => {
115
- _navigator.replace(path, state);
116
- }, 1);
117
- };
118
- _navigator.preload = async (path, isReplace, query) => {
119
- const [originPath = "", search = ""] = path.split("?");
120
- let matchPath = originPath.toLowerCase();
121
- const currentRoute = matchRoutes(routes, matchPath)?.[0]?.route;
122
- query = query || queryString.parse(search, { parseBooleans: true, parseNumbers: true });
123
- if (!currentRoute?.Component.config) {
124
- const pageModule = await currentRoute?.Component.load();
125
- await pageModule.default?.emitOnLoad?.({ isPreload: true, query });
126
- } else {
127
- await currentRoute?.Component?.emitOnLoad?.({ isPreload: true, query });
128
- }
129
- if (isReplace) {
130
- _navigator.replace(path);
338
+ var mode = options.mode, _options_initPathname = options.initPathname, initPathname = _options_initPathname === void 0 ? "/" : _options_initPathname, routes = options.routes;
339
+ var originHistory;
340
+ if (mode === "static") {
341
+ originHistory = createMemoryHistory({
342
+ initialEntries: [
343
+ initPathname
344
+ ]
345
+ });
346
+ } else if (mode === "browser") {
347
+ originHistory = createBrowserHistory();
131
348
  } else {
132
- _navigator.push(path);
349
+ originHistory = createHashHistory();
133
350
  }
134
- };
135
- return _navigator;
351
+ _navigator = originHistory;
352
+ var initialStack = [
353
+ {
354
+ pathname: _navigator.location.pathname
355
+ }
356
+ ];
357
+ var stack = _navigator.stack = initialStack;
358
+ _navigator.listen(function(param) {
359
+ var location = param.location, action = param.action;
360
+ var pathname = location.pathname;
361
+ if (action === "PUSH") {
362
+ stack.push({
363
+ pathname: pathname
364
+ });
365
+ } else if (action === "REPLACE") {
366
+ stack.pop();
367
+ stack.push({
368
+ pathname: pathname
369
+ });
370
+ } else if (action === "POP") {
371
+ stack.pop();
372
+ }
373
+ console.log("router", action, pathname, stack);
374
+ });
375
+ _navigator.reLaunch = function(path, state) {
376
+ var _stack_;
377
+ var shouldBlack = -stack.length + 1;
378
+ if (shouldBlack < 0) _navigator.go(shouldBlack);
379
+ if (((_stack_ = stack[0]) === null || _stack_ === void 0 ? void 0 : _stack_.pathname) === path) return;
380
+ setTimeout(function() {
381
+ _navigator.replace(path, state);
382
+ }, 1);
383
+ };
384
+ _navigator.preload = function() {
385
+ var _ref = _async_to_generator(function(path, isReplace, query) {
386
+ var _matchRoutes_, _matchRoutes, _path_split, tmp, originPath, tmp1, search, matchPath, currentRoute, _pageModule_default_emitOnLoad, _pageModule_default, pageModule, _currentRoute_Component_emitOnLoad, _currentRoute_Component;
387
+ return _ts_generator(this, function(_state) {
388
+ switch(_state.label){
389
+ case 0:
390
+ _path_split = _sliced_to_array(path.split("?"), 2), tmp = _path_split[0], originPath = tmp === void 0 ? "" : tmp, tmp1 = _path_split[1], search = tmp1 === void 0 ? "" : tmp1;
391
+ matchPath = originPath.toLowerCase();
392
+ currentRoute = (_matchRoutes = matchRoutes(routes, matchPath)) === null || _matchRoutes === void 0 ? void 0 : (_matchRoutes_ = _matchRoutes[0]) === null || _matchRoutes_ === void 0 ? void 0 : _matchRoutes_.route;
393
+ query = query || queryString.parse(search, {
394
+ parseBooleans: true,
395
+ parseNumbers: true
396
+ });
397
+ if (!!(currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.Component.config)) return [
398
+ 3,
399
+ 3
400
+ ];
401
+ return [
402
+ 4,
403
+ currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.Component.load()
404
+ ];
405
+ case 1:
406
+ pageModule = _state.sent();
407
+ return [
408
+ 4,
409
+ (_pageModule_default = pageModule.default) === null || _pageModule_default === void 0 ? void 0 : (_pageModule_default_emitOnLoad = _pageModule_default.emitOnLoad) === null || _pageModule_default_emitOnLoad === void 0 ? void 0 : _pageModule_default_emitOnLoad.call(_pageModule_default, {
410
+ isPreload: true,
411
+ query: query
412
+ })
413
+ ];
414
+ case 2:
415
+ _state.sent();
416
+ return [
417
+ 3,
418
+ 5
419
+ ];
420
+ case 3:
421
+ return [
422
+ 4,
423
+ currentRoute === null || currentRoute === void 0 ? void 0 : (_currentRoute_Component = currentRoute.Component) === null || _currentRoute_Component === void 0 ? void 0 : (_currentRoute_Component_emitOnLoad = _currentRoute_Component.emitOnLoad) === null || _currentRoute_Component_emitOnLoad === void 0 ? void 0 : _currentRoute_Component_emitOnLoad.call(_currentRoute_Component, {
424
+ isPreload: true,
425
+ query: query
426
+ })
427
+ ];
428
+ case 4:
429
+ _state.sent();
430
+ _state.label = 5;
431
+ case 5:
432
+ if (isReplace) {
433
+ _navigator.replace(path);
434
+ } else {
435
+ _navigator.push(path);
436
+ }
437
+ return [
438
+ 2
439
+ ];
440
+ }
441
+ });
442
+ });
443
+ return function(path, isReplace, query) {
444
+ return _ref.apply(this, arguments);
445
+ };
446
+ }();
447
+ return _navigator;
136
448
  }
137
- var getClientNavigator = () => _navigator;
138
- var routerReady = loadableReady;
139
- export {
140
- Link,
141
- Router,
142
- createNavigator,
143
- getClientNavigator,
144
- getRoutes,
145
- routerReady
449
+ var getClientNavigator = function() {
450
+ return _navigator;
146
451
  };
452
+ var routerReady = loadableReady;
453
+ export { Link, Router, createNavigator, getClientNavigator, getRoutes, routerReady };
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "@xfe-repo/web-router",
3
- "version": "1.0.5",
3
+ "version": "1.1.0",
4
4
  "sideEffects": false,
5
+ "module": "dist/index.js",
6
+ "types": "dist/index.d.ts",
5
7
  "exports": {
6
8
  ".": {
7
9
  "import": {
@@ -11,10 +13,6 @@
11
13
  "require": {
12
14
  "types": "./dist/index.d.ts",
13
15
  "default": "./dist/index.js"
14
- },
15
- "default": {
16
- "types": "./dist/index.d.ts",
17
- "default": "./dist/index.js"
18
16
  }
19
17
  }
20
18
  },
@@ -22,18 +20,18 @@
22
20
  "dist"
23
21
  ],
24
22
  "dependencies": {
25
- "@loadable/component": "^5.15.3",
23
+ "@loadable/component": "^5.16.4",
26
24
  "history": "^5.3.0",
27
25
  "query-string": "^7.1.3",
28
- "react-router-dom": "^6.11.1"
26
+ "react-router-dom": "^6.26.2"
29
27
  },
30
28
  "devDependencies": {
31
- "@types/loadable__component": "^5.13.8",
32
- "@types/node": "^20.10.4",
33
- "@types/react": "^18.2.0",
34
- "@xfe-repo/web-register": "1.0.3",
29
+ "@types/loadable__component": "^5.13.9",
30
+ "@types/node": "^20.16.5",
31
+ "@types/react": "^18",
32
+ "@xfe-repo/eslint-config": "0.0.2",
35
33
  "@xfe-repo/typescript-config": "0.0.3",
36
- "@xfe-repo/eslint-config": "0.0.2"
34
+ "@xfe-repo/web-register": "1.1.0"
37
35
  },
38
36
  "scripts": {
39
37
  "build": "tsup",