swico 0.5.0-beta10 → 0.5.0-beta12
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
package/src/index.react.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare const Link: FC<{
|
|
|
10
10
|
children: ReactNode;
|
|
11
11
|
}>;
|
|
12
12
|
export { Outlet } from 'react-router-dom';
|
|
13
|
-
export { useLocation } from './template/react/
|
|
13
|
+
export { useLocation } from './template/react/index';
|
|
14
14
|
export interface DefineSwicoConfigType {
|
|
15
15
|
(env: 'base', config: CustomConfigType['base']): any;
|
|
16
16
|
(env: 'dev', config: CustomConfigType['dev']): any;
|
package/src/index.react.js
CHANGED
|
@@ -13,8 +13,8 @@ var Link = function (_a) {
|
|
|
13
13
|
exports.Link = Link;
|
|
14
14
|
var react_router_dom_2 = require("react-router-dom");
|
|
15
15
|
Object.defineProperty(exports, "Outlet", { enumerable: true, get: function () { return react_router_dom_2.Outlet; } });
|
|
16
|
-
var
|
|
17
|
-
Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return
|
|
16
|
+
var index_1 = require("./template/react/index");
|
|
17
|
+
Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return index_1.useLocation; } });
|
|
18
18
|
var defineConfig = function (env, config) { return config; };
|
|
19
19
|
exports.defineConfig = defineConfig;
|
|
20
20
|
var defineGlobal = function (config) {
|
|
@@ -26,13 +26,19 @@ var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
|
|
|
26
26
|
}
|
|
27
27
|
return true;
|
|
28
28
|
};
|
|
29
|
+
console.log('routes1', routes_1.routes);
|
|
29
30
|
var useLocation = function () {
|
|
30
31
|
var _a, _b;
|
|
31
32
|
var location = (0, react_router_dom_1.useLocation)();
|
|
32
33
|
var params = (0, react_router_dom_1.useParams)();
|
|
33
34
|
var search = location.search, hash = location.hash, pathname = location.pathname;
|
|
35
|
+
console.log('routes2', routes_1.routes);
|
|
34
36
|
var pathNameList = (0, history_1.getPathNameList)(routes_1.routes);
|
|
35
|
-
|
|
37
|
+
console.log('pathNameList', pathNameList);
|
|
38
|
+
var name = (_a = pathNameList.find(function (item) {
|
|
39
|
+
return (Object.keys(params).length > 0 && compareURLPatterns(pathname, item.path)) ||
|
|
40
|
+
item.path === pathname;
|
|
41
|
+
})) === null || _a === void 0 ? void 0 : _a.name;
|
|
36
42
|
var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
|
|
37
43
|
return {
|
|
38
44
|
name: name,
|
|
@@ -26,6 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.useLocation = void 0;
|
|
29
30
|
var client_1 = require("react-dom/client");
|
|
30
31
|
var react_1 = __importStar(require("react"));
|
|
31
32
|
var react_router_dom_1 = require("react-router-dom");
|
|
@@ -35,6 +36,50 @@ var history_1 = require("./history");
|
|
|
35
36
|
var config_1 = require("./config");
|
|
36
37
|
require("../global");
|
|
37
38
|
var layout_1 = __importDefault(require("../layout"));
|
|
39
|
+
var hooks_1 = require("react-router/dist/lib/hooks");
|
|
40
|
+
var qs_1 = __importDefault(require("qs"));
|
|
41
|
+
console.log('routes', routes_1.routes);
|
|
42
|
+
var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
|
|
43
|
+
var patternWithValuesParts = urlPatternWithValues.split('/');
|
|
44
|
+
var patternWithParamsParts = urlPatternWithParams.split('/');
|
|
45
|
+
if (patternWithValuesParts.length !== patternWithParamsParts.length) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
for (var i = 0; i < patternWithValuesParts.length; i++) {
|
|
49
|
+
var valuePart = patternWithValuesParts[i];
|
|
50
|
+
var paramPart = patternWithParamsParts[i];
|
|
51
|
+
if (paramPart.startsWith(':') && paramPart !== '') {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (valuePart !== paramPart) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
};
|
|
60
|
+
var useLocation = function () {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
var location = (0, hooks_1.useLocation)();
|
|
63
|
+
var params = (0, react_router_dom_1.useParams)();
|
|
64
|
+
var search = location.search, hash = location.hash, pathname = location.pathname;
|
|
65
|
+
console.log('routes1', routes_1.routes);
|
|
66
|
+
var pathNameList = (0, history_1.getPathNameList)(routes_1.routes);
|
|
67
|
+
var name = (_a = pathNameList.find(function (item) {
|
|
68
|
+
return (Object.keys(params).length > 0 && compareURLPatterns(pathname, item.path)) ||
|
|
69
|
+
item.path === pathname;
|
|
70
|
+
})) === null || _a === void 0 ? void 0 : _a.name;
|
|
71
|
+
var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
|
|
72
|
+
return {
|
|
73
|
+
name: name,
|
|
74
|
+
path: pathname,
|
|
75
|
+
pathname: (_b = window === null || window === void 0 ? void 0 : window.location) === null || _b === void 0 ? void 0 : _b.pathname,
|
|
76
|
+
search: search,
|
|
77
|
+
query: query,
|
|
78
|
+
hash: hash,
|
|
79
|
+
params: params
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
exports.useLocation = useLocation;
|
|
38
83
|
var renderChildrenRouteList = function (childrenRoutes, ancPathKey) {
|
|
39
84
|
return childrenRoutes === null || childrenRoutes === void 0 ? void 0 : childrenRoutes.map(function (item) {
|
|
40
85
|
var component = item.component, path = item.path, children = item.children, redirect = item.redirect;
|
|
@@ -44,6 +89,7 @@ var renderChildrenRouteList = function (childrenRoutes, ancPathKey) {
|
|
|
44
89
|
};
|
|
45
90
|
var App = function () {
|
|
46
91
|
var _a = (0, history_1.getHistory)(config_1.routerBase, config_1.routerType, routes_1.routes), history = _a.history, originalHistory = _a.originalHistory;
|
|
92
|
+
console.log('routes2', routes_1.routes);
|
|
47
93
|
if (config_1.routerBase && config_1.routerBase !== '/') {
|
|
48
94
|
if (config_1.routerType === 'browser' && window.location.pathname === '/') {
|
|
49
95
|
window.location.replace("".concat(config_1.routerBase));
|