swico 0.9.0-beta2 → 0.9.0-beta4
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ConfigRouterType } from '../../../utils/config';
|
|
2
1
|
import { SwicoHistoryType } from '../../../typings/global-type';
|
|
3
|
-
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export declare const Router: (children: any) => React.DetailedReactHTMLElement<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
|
|
4
4
|
export declare const compareURLPatterns: (urlPatternWithValues: string, urlPatternWithParams: string) => boolean;
|
|
5
5
|
export declare const interpolatePath: (pathTemplate: string, params: Record<string, any>) => string;
|
|
6
6
|
export declare const formatAncPath: (ancPath: string) => string;
|
|
@@ -9,4 +9,3 @@ export declare const pathNameList: {
|
|
|
9
9
|
name: string;
|
|
10
10
|
}[];
|
|
11
11
|
export declare let history: SwicoHistoryType;
|
|
12
|
-
export declare const getOriHistory: (routerType: ConfigRouterType['type']) => import("history").HashHistory;
|
|
@@ -3,13 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.history = exports.pathNameList = exports.formatAncPath = exports.interpolatePath = exports.compareURLPatterns = exports.Router = void 0;
|
|
7
7
|
var qs_1 = __importDefault(require("qs"));
|
|
8
8
|
var history_1 = require("history");
|
|
9
9
|
var routes_1 = __importDefault(require("./routes"));
|
|
10
10
|
var config_1 = require("./config");
|
|
11
11
|
var react_router_dom_1 = require("react-router-dom");
|
|
12
|
-
|
|
12
|
+
var react_1 = __importDefault(require("react"));
|
|
13
|
+
var Router = function (children) {
|
|
14
|
+
return react_1.default.createElement(react_router_dom_1.unstable_HistoryRouter, { basename: config_1.routerBase, history: getOriHistory(config_1.routerType) }, children);
|
|
15
|
+
};
|
|
16
|
+
exports.Router = Router;
|
|
13
17
|
var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
|
|
14
18
|
var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
|
|
15
19
|
var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
|
|
@@ -87,13 +91,13 @@ var getPathNameList = function (routes) {
|
|
|
87
91
|
};
|
|
88
92
|
exports.pathNameList = getPathNameList(routes_1.default);
|
|
89
93
|
var getLocation = function (originalHistory) {
|
|
90
|
-
var _a = originalHistory.location, pathname = _a.pathname, hash = _a.hash, search = _a.search,
|
|
94
|
+
var _a = originalHistory.location, pathname = _a.pathname, hash = _a.hash, search = _a.search, state = _a.state;
|
|
91
95
|
var routerBaseLength = formatRouterBase.length;
|
|
92
96
|
var path = pathname.slice(routerBaseLength);
|
|
93
97
|
var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || (0, exports.compareURLPatterns)(path, item.path); });
|
|
94
98
|
var params = interpolatePathParams(matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.path, path);
|
|
95
99
|
return {
|
|
96
|
-
state: state,
|
|
100
|
+
state: state !== null && state !== void 0 ? state : {},
|
|
97
101
|
hash: hash,
|
|
98
102
|
search: search,
|
|
99
103
|
pathname: pathname,
|
|
@@ -165,4 +169,3 @@ var getOriHistory = function (routerType) {
|
|
|
165
169
|
};
|
|
166
170
|
return originalHistory;
|
|
167
171
|
};
|
|
168
|
-
exports.getOriHistory = getOriHistory;
|
|
@@ -43,13 +43,12 @@ var renderChildrenRouteList = function (childrenRoutes, ancPathKey) {
|
|
|
43
43
|
});
|
|
44
44
|
};
|
|
45
45
|
var App = function () {
|
|
46
|
-
var originalHistory = (0, history_1.getOriHistory)(config_1.routerType);
|
|
47
46
|
if (config_1.routerBase && config_1.routerBase !== '/') {
|
|
48
47
|
if (config_1.routerType === 'browser' && window.location.pathname === '/') {
|
|
49
48
|
window.location.replace("".concat(config_1.routerBase));
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
|
-
return (react_1.default.createElement(history_1.
|
|
51
|
+
return (react_1.default.createElement(history_1.Router, null,
|
|
53
52
|
react_1.default.createElement(react_router_dom_1.Routes, null,
|
|
54
53
|
react_1.default.createElement(react_router_dom_1.Route, { element: react_1.default.createElement(layout_1.default, null), path: '' }, renderChildrenRouteList(routes_1.default, '')))));
|
|
55
54
|
};
|
|
@@ -22,7 +22,7 @@ var useLocation = function () {
|
|
|
22
22
|
var _a, _b;
|
|
23
23
|
var location = (0, react_router_dom_1.useLocation)();
|
|
24
24
|
var params = (0, react_router_dom_1.useParams)();
|
|
25
|
-
var search = location.search, hash = location.hash, pathname = location.pathname,
|
|
25
|
+
var search = location.search, hash = location.hash, pathname = location.pathname, state = location.state;
|
|
26
26
|
var name = (_a = history_1.pathNameList.find(function (item) {
|
|
27
27
|
return (Object.keys(params).length > 0 && (0, history_1.compareURLPatterns)(pathname, item.path)) ||
|
|
28
28
|
item.path === pathname;
|
|
@@ -30,7 +30,7 @@ var useLocation = function () {
|
|
|
30
30
|
var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
|
|
31
31
|
return {
|
|
32
32
|
name: name,
|
|
33
|
-
state: state,
|
|
33
|
+
state: state !== null && state !== void 0 ? state : {},
|
|
34
34
|
path: pathname,
|
|
35
35
|
pathname: (_b = window === null || window === void 0 ? void 0 : window.location) === null || _b === void 0 ? void 0 : _b.pathname,
|
|
36
36
|
search: '',
|