@xfe-repo/web-router 1.2.2 → 1.2.3
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 +2 -8
- package/dist/index.d.ts +2 -8
- package/dist/index.js +12 -52
- package/dist/index.mjs +11 -51
- package/package.json +6 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { History } from 'history';
|
|
2
2
|
import { LoadableComponent, loadableReady } from '@loadable/component';
|
|
3
|
-
import { ParsedQuery } from '
|
|
3
|
+
import { ParsedQuery } from '@xfe-repo/web-utils/tools';
|
|
4
4
|
import React, { ReactElement, PropsWithChildren, ComponentType } from 'react';
|
|
5
5
|
import { RegisterComponentStatic } from '@xfe-repo/web-register';
|
|
6
6
|
import { LinkProps as LinkProps$1 } from 'react-router-dom';
|
|
@@ -32,17 +32,11 @@ declare const Router: React.MemoExoticComponent<(props: RouterProps) => react_js
|
|
|
32
32
|
|
|
33
33
|
type LinkProps = Omit<LinkProps$1, 'to'> & {
|
|
34
34
|
to: string;
|
|
35
|
-
reLaunch?: boolean;
|
|
36
35
|
preload?: boolean;
|
|
37
36
|
};
|
|
38
37
|
declare const Link: React.MemoExoticComponent<(props: LinkProps) => react_jsx_runtime.JSX.Element>;
|
|
39
38
|
|
|
40
|
-
type NavigatorStack = {
|
|
41
|
-
pathname: string;
|
|
42
|
-
};
|
|
43
39
|
interface NavigatorType extends History {
|
|
44
|
-
stack: NavigatorStack[];
|
|
45
|
-
reLaunch: (path: string, state?: any) => void;
|
|
46
40
|
preload: (path: string, isReplace?: boolean, query?: ParsedQuery<string | number | boolean>) => Promise<void>;
|
|
47
41
|
leave: (path: string) => void;
|
|
48
42
|
}
|
|
@@ -56,4 +50,4 @@ declare function createNavigator(options: CreateNavigatorOptions): NavigatorType
|
|
|
56
50
|
declare const getClientNavigator: () => NavigatorType;
|
|
57
51
|
declare const routerReady: typeof loadableReady;
|
|
58
52
|
|
|
59
|
-
export { type CreateNavigatorOptions, type GetRoutesConfig, Link, type
|
|
53
|
+
export { type CreateNavigatorOptions, type GetRoutesConfig, Link, type NavigatorType, type PageComponent, type RouteConfig, Router, createNavigator, getClientNavigator, getRoutes, routerDynamicRegx, routerIndexRegx, routerReady };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { History } from 'history';
|
|
2
2
|
import { LoadableComponent, loadableReady } from '@loadable/component';
|
|
3
|
-
import { ParsedQuery } from '
|
|
3
|
+
import { ParsedQuery } from '@xfe-repo/web-utils/tools';
|
|
4
4
|
import React, { ReactElement, PropsWithChildren, ComponentType } from 'react';
|
|
5
5
|
import { RegisterComponentStatic } from '@xfe-repo/web-register';
|
|
6
6
|
import { LinkProps as LinkProps$1 } from 'react-router-dom';
|
|
@@ -32,17 +32,11 @@ declare const Router: React.MemoExoticComponent<(props: RouterProps) => react_js
|
|
|
32
32
|
|
|
33
33
|
type LinkProps = Omit<LinkProps$1, 'to'> & {
|
|
34
34
|
to: string;
|
|
35
|
-
reLaunch?: boolean;
|
|
36
35
|
preload?: boolean;
|
|
37
36
|
};
|
|
38
37
|
declare const Link: React.MemoExoticComponent<(props: LinkProps) => react_jsx_runtime.JSX.Element>;
|
|
39
38
|
|
|
40
|
-
type NavigatorStack = {
|
|
41
|
-
pathname: string;
|
|
42
|
-
};
|
|
43
39
|
interface NavigatorType extends History {
|
|
44
|
-
stack: NavigatorStack[];
|
|
45
|
-
reLaunch: (path: string, state?: any) => void;
|
|
46
40
|
preload: (path: string, isReplace?: boolean, query?: ParsedQuery<string | number | boolean>) => Promise<void>;
|
|
47
41
|
leave: (path: string) => void;
|
|
48
42
|
}
|
|
@@ -56,4 +50,4 @@ declare function createNavigator(options: CreateNavigatorOptions): NavigatorType
|
|
|
56
50
|
declare const getClientNavigator: () => NavigatorType;
|
|
57
51
|
declare const routerReady: typeof loadableReady;
|
|
58
52
|
|
|
59
|
-
export { type CreateNavigatorOptions, type GetRoutesConfig, Link, type
|
|
53
|
+
export { type CreateNavigatorOptions, type GetRoutesConfig, Link, type NavigatorType, type PageComponent, type RouteConfig, Router, createNavigator, getClientNavigator, getRoutes, routerDynamicRegx, routerIndexRegx, routerReady };
|
package/dist/index.js
CHANGED
|
@@ -290,8 +290,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
290
290
|
var import_history = require("history");
|
|
291
291
|
var import_component2 = require("@loadable/component");
|
|
292
292
|
var import_react_router_dom3 = require("react-router-dom");
|
|
293
|
-
var
|
|
294
|
-
var import_env = require("@xfe-repo/web-utils/env");
|
|
293
|
+
var import_tools = require("@xfe-repo/web-utils/tools");
|
|
295
294
|
__reExport(src_exports, require("react-router-dom"), module.exports);
|
|
296
295
|
// src/routes.ts
|
|
297
296
|
var import_component = __toESM(require("@loadable/component"));
|
|
@@ -366,36 +365,29 @@ var import_react2 = require("react");
|
|
|
366
365
|
var import_react_router_dom2 = require("react-router-dom");
|
|
367
366
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
368
367
|
var Link = (0, import_react2.memo)(function(props) {
|
|
369
|
-
var to = props.to, children = props.children,
|
|
368
|
+
var to = props.to, children = props.children, preload = props.preload, replace = props.replace, className = props.className, target = props.target;
|
|
370
369
|
var _navigator2 = (0, import_react2.useMemo)(function() {
|
|
371
370
|
return getClientNavigator();
|
|
372
371
|
}, []);
|
|
373
372
|
if (/http(s)?:\/{2}/.test(to)) {
|
|
374
373
|
var handleLink = function(e) {
|
|
375
374
|
e.preventDefault();
|
|
376
|
-
|
|
375
|
+
if (target === "_blank") {
|
|
376
|
+
window.open(to);
|
|
377
|
+
} else {
|
|
378
|
+
window.location.href = to;
|
|
379
|
+
}
|
|
377
380
|
};
|
|
378
381
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", {
|
|
379
382
|
href: to,
|
|
380
383
|
onClick: handleLink,
|
|
381
384
|
className: className,
|
|
382
|
-
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
if (reLaunch) {
|
|
386
|
-
var handleLink1 = function(e) {
|
|
387
|
-
e.preventDefault();
|
|
388
|
-
_navigator2.reLaunch(to);
|
|
389
|
-
};
|
|
390
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", {
|
|
391
|
-
href: to,
|
|
392
|
-
onClick: handleLink1,
|
|
393
|
-
className: className,
|
|
385
|
+
target: target,
|
|
394
386
|
children: children
|
|
395
387
|
});
|
|
396
388
|
}
|
|
397
389
|
if (preload) {
|
|
398
|
-
var
|
|
390
|
+
var handleLink1 = function() {
|
|
399
391
|
var _ref = _async_to_generator(function(e) {
|
|
400
392
|
return _ts_generator(this, function(_state) {
|
|
401
393
|
switch(_state.label){
|
|
@@ -413,13 +405,13 @@ var Link = (0, import_react2.memo)(function(props) {
|
|
|
413
405
|
}
|
|
414
406
|
});
|
|
415
407
|
});
|
|
416
|
-
return function
|
|
408
|
+
return function handleLink1(e) {
|
|
417
409
|
return _ref.apply(this, arguments);
|
|
418
410
|
};
|
|
419
411
|
}();
|
|
420
412
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", {
|
|
421
413
|
href: to,
|
|
422
|
-
onClick:
|
|
414
|
+
onClick: handleLink1,
|
|
423
415
|
className: className,
|
|
424
416
|
children: children
|
|
425
417
|
});
|
|
@@ -443,38 +435,6 @@ function createNavigator(options) {
|
|
|
443
435
|
originHistory = (0, import_history.createHashHistory)();
|
|
444
436
|
}
|
|
445
437
|
_navigator = originHistory;
|
|
446
|
-
var initialStack = [
|
|
447
|
-
{
|
|
448
|
-
pathname: _navigator.location.pathname
|
|
449
|
-
}
|
|
450
|
-
];
|
|
451
|
-
var stack = _navigator.stack = initialStack;
|
|
452
|
-
_navigator.listen(function(param) {
|
|
453
|
-
var location = param.location, action = param.action;
|
|
454
|
-
var pathname = location.pathname;
|
|
455
|
-
if (action === "PUSH") {
|
|
456
|
-
stack.push({
|
|
457
|
-
pathname: pathname
|
|
458
|
-
});
|
|
459
|
-
} else if (action === "REPLACE") {
|
|
460
|
-
stack.pop();
|
|
461
|
-
stack.push({
|
|
462
|
-
pathname: pathname
|
|
463
|
-
});
|
|
464
|
-
} else if (action === "POP") {
|
|
465
|
-
stack.pop();
|
|
466
|
-
}
|
|
467
|
-
if (!import_env.isProduction) console.log("router", action, pathname, stack);
|
|
468
|
-
});
|
|
469
|
-
_navigator.reLaunch = function(path, state) {
|
|
470
|
-
var _stack_;
|
|
471
|
-
var shouldBlack = -stack.length + 1;
|
|
472
|
-
if (shouldBlack < 0) _navigator.go(shouldBlack);
|
|
473
|
-
if (((_stack_ = stack[0]) === null || _stack_ === void 0 ? void 0 : _stack_.pathname) === path) return;
|
|
474
|
-
setTimeout(function() {
|
|
475
|
-
_navigator.replace(path, state);
|
|
476
|
-
}, 1);
|
|
477
|
-
};
|
|
478
438
|
_navigator.preload = function() {
|
|
479
439
|
var _ref = _async_to_generator(function(path, isReplace, query) {
|
|
480
440
|
var _, _this, _path_split, tmp, originPath, tmp1, search, matchPath, currentRoute, _pageModule_default_emitOnLoad, _pageModule_default, pageModule, _currentRoute_Component_emitOnLoad, _currentRoute_Component;
|
|
@@ -484,7 +444,7 @@ function createNavigator(options) {
|
|
|
484
444
|
_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;
|
|
485
445
|
matchPath = originPath.toLowerCase();
|
|
486
446
|
currentRoute = (_this = (0, import_react_router_dom3.matchRoutes)(routes, matchPath)) === null || _this === void 0 ? void 0 : (_ = _this[0]) === null || _ === void 0 ? void 0 : _.route;
|
|
487
|
-
query = query ||
|
|
447
|
+
query = query || import_tools.queryString.parse(search, {
|
|
488
448
|
parseBooleans: true,
|
|
489
449
|
parseNumbers: true
|
|
490
450
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -200,8 +200,7 @@ function _ts_generator(thisArg, body) {
|
|
|
200
200
|
import { createHashHistory, createBrowserHistory, createMemoryHistory } from "history";
|
|
201
201
|
import { loadableReady } from "@loadable/component";
|
|
202
202
|
import { matchRoutes } from "react-router-dom";
|
|
203
|
-
import queryString from "
|
|
204
|
-
import { isProduction } from "@xfe-repo/web-utils/env";
|
|
203
|
+
import { queryString } from "@xfe-repo/web-utils/tools";
|
|
205
204
|
export * from "react-router-dom";
|
|
206
205
|
// src/routes.ts
|
|
207
206
|
import loadable from "@loadable/component";
|
|
@@ -276,36 +275,29 @@ import { memo as memo2, useMemo } from "react";
|
|
|
276
275
|
import { Link as OriginalLink } from "react-router-dom";
|
|
277
276
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
278
277
|
var Link = memo2(function(props) {
|
|
279
|
-
var to = props.to, children = props.children,
|
|
278
|
+
var to = props.to, children = props.children, preload = props.preload, replace = props.replace, className = props.className, target = props.target;
|
|
280
279
|
var _navigator2 = useMemo(function() {
|
|
281
280
|
return getClientNavigator();
|
|
282
281
|
}, []);
|
|
283
282
|
if (/http(s)?:\/{2}/.test(to)) {
|
|
284
283
|
var handleLink = function(e) {
|
|
285
284
|
e.preventDefault();
|
|
286
|
-
|
|
285
|
+
if (target === "_blank") {
|
|
286
|
+
window.open(to);
|
|
287
|
+
} else {
|
|
288
|
+
window.location.href = to;
|
|
289
|
+
}
|
|
287
290
|
};
|
|
288
291
|
return /* @__PURE__ */ jsx2("a", {
|
|
289
292
|
href: to,
|
|
290
293
|
onClick: handleLink,
|
|
291
294
|
className: className,
|
|
292
|
-
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
if (reLaunch) {
|
|
296
|
-
var handleLink1 = function(e) {
|
|
297
|
-
e.preventDefault();
|
|
298
|
-
_navigator2.reLaunch(to);
|
|
299
|
-
};
|
|
300
|
-
return /* @__PURE__ */ jsx2("a", {
|
|
301
|
-
href: to,
|
|
302
|
-
onClick: handleLink1,
|
|
303
|
-
className: className,
|
|
295
|
+
target: target,
|
|
304
296
|
children: children
|
|
305
297
|
});
|
|
306
298
|
}
|
|
307
299
|
if (preload) {
|
|
308
|
-
var
|
|
300
|
+
var handleLink1 = function() {
|
|
309
301
|
var _ref = _async_to_generator(function(e) {
|
|
310
302
|
return _ts_generator(this, function(_state) {
|
|
311
303
|
switch(_state.label){
|
|
@@ -323,13 +315,13 @@ var Link = memo2(function(props) {
|
|
|
323
315
|
}
|
|
324
316
|
});
|
|
325
317
|
});
|
|
326
|
-
return function
|
|
318
|
+
return function handleLink1(e) {
|
|
327
319
|
return _ref.apply(this, arguments);
|
|
328
320
|
};
|
|
329
321
|
}();
|
|
330
322
|
return /* @__PURE__ */ jsx2("a", {
|
|
331
323
|
href: to,
|
|
332
|
-
onClick:
|
|
324
|
+
onClick: handleLink1,
|
|
333
325
|
className: className,
|
|
334
326
|
children: children
|
|
335
327
|
});
|
|
@@ -353,38 +345,6 @@ function createNavigator(options) {
|
|
|
353
345
|
originHistory = createHashHistory();
|
|
354
346
|
}
|
|
355
347
|
_navigator = originHistory;
|
|
356
|
-
var initialStack = [
|
|
357
|
-
{
|
|
358
|
-
pathname: _navigator.location.pathname
|
|
359
|
-
}
|
|
360
|
-
];
|
|
361
|
-
var stack = _navigator.stack = initialStack;
|
|
362
|
-
_navigator.listen(function(param) {
|
|
363
|
-
var location = param.location, action = param.action;
|
|
364
|
-
var pathname = location.pathname;
|
|
365
|
-
if (action === "PUSH") {
|
|
366
|
-
stack.push({
|
|
367
|
-
pathname: pathname
|
|
368
|
-
});
|
|
369
|
-
} else if (action === "REPLACE") {
|
|
370
|
-
stack.pop();
|
|
371
|
-
stack.push({
|
|
372
|
-
pathname: pathname
|
|
373
|
-
});
|
|
374
|
-
} else if (action === "POP") {
|
|
375
|
-
stack.pop();
|
|
376
|
-
}
|
|
377
|
-
if (!isProduction) console.log("router", action, pathname, stack);
|
|
378
|
-
});
|
|
379
|
-
_navigator.reLaunch = function(path, state) {
|
|
380
|
-
var _stack_;
|
|
381
|
-
var shouldBlack = -stack.length + 1;
|
|
382
|
-
if (shouldBlack < 0) _navigator.go(shouldBlack);
|
|
383
|
-
if (((_stack_ = stack[0]) === null || _stack_ === void 0 ? void 0 : _stack_.pathname) === path) return;
|
|
384
|
-
setTimeout(function() {
|
|
385
|
-
_navigator.replace(path, state);
|
|
386
|
-
}, 1);
|
|
387
|
-
};
|
|
388
348
|
_navigator.preload = function() {
|
|
389
349
|
var _ref = _async_to_generator(function(path, isReplace, query) {
|
|
390
350
|
var _matchRoutes_, _matchRoutes, _path_split, tmp, originPath, tmp1, search, matchPath, currentRoute, _pageModule_default_emitOnLoad, _pageModule_default, pageModule, _currentRoute_Component_emitOnLoad, _currentRoute_Component;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xfe-repo/web-router",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,9 +22,7 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@loadable/component": "^5.16.4",
|
|
24
24
|
"history": "^5.3.0",
|
|
25
|
-
"
|
|
26
|
-
"react-router-dom": "6.28.0",
|
|
27
|
-
"@xfe-repo/web-utils": "1.3.5"
|
|
25
|
+
"react-router-dom": "6.28.0"
|
|
28
26
|
},
|
|
29
27
|
"devDependencies": {
|
|
30
28
|
"@types/loadable__component": "^5.13.9",
|
|
@@ -32,7 +30,10 @@
|
|
|
32
30
|
"@types/react": "^18",
|
|
33
31
|
"@xfe-repo/eslint-config": "0.0.5",
|
|
34
32
|
"@xfe-repo/typescript-config": "0.0.6",
|
|
35
|
-
"@xfe-repo/web-register": "1.3.
|
|
33
|
+
"@xfe-repo/web-register": "1.3.5"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@xfe-repo/web-utils": "1.3.7"
|
|
36
37
|
},
|
|
37
38
|
"publishConfig": {
|
|
38
39
|
"registry": "https://registry.npmjs.org/"
|