swico 0.9.0-beta14 → 0.9.0-beta16
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,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SwicoHistoryType } from '../../../typings/global-type';
|
|
1
|
+
import { SwicoHistoryType, SwicoLocationType } from '../../../typings/global-type';
|
|
3
2
|
export declare const compareURLPatterns: (urlPatternWithValues: string, urlPatternWithParams: string) => boolean;
|
|
4
3
|
export declare const interpolatePath: (pathTemplate: string, params: Record<string, any>) => string;
|
|
5
4
|
export declare const formatAncPath: (ancPath: string) => string;
|
|
@@ -7,5 +6,12 @@ export declare const pathNameList: {
|
|
|
7
6
|
path: string;
|
|
8
7
|
name: string;
|
|
9
8
|
}[];
|
|
9
|
+
export declare const getHistory: (router: any) => {
|
|
10
|
+
go: (delta: any) => void;
|
|
11
|
+
forward: () => void;
|
|
12
|
+
back: () => void;
|
|
13
|
+
push: (to: any) => void;
|
|
14
|
+
replace: (to: any) => void;
|
|
15
|
+
readonly location: SwicoLocationType;
|
|
16
|
+
};
|
|
10
17
|
export declare let history: SwicoHistoryType;
|
|
11
|
-
export declare const getRouter: (routerType: ConfigRouterType['type']) => import("@remix-run/router").Router;
|
|
@@ -3,14 +3,10 @@ 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.
|
|
7
|
-
var index_1 = require("./index");
|
|
6
|
+
exports.history = exports.getHistory = exports.pathNameList = exports.formatAncPath = exports.interpolatePath = exports.compareURLPatterns = void 0;
|
|
8
7
|
var qs_1 = __importDefault(require("qs"));
|
|
9
8
|
var routes_1 = __importDefault(require("./routes"));
|
|
10
9
|
var config_1 = require("./config");
|
|
11
|
-
var layout_1 = __importDefault(require("../../layout"));
|
|
12
|
-
var react_router_dom_1 = require("react-router-dom");
|
|
13
|
-
var react_1 = __importDefault(require("react"));
|
|
14
10
|
var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
|
|
15
11
|
var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
|
|
16
12
|
var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
|
|
@@ -127,16 +123,8 @@ var getFormatHistoryOption = function (to, pathList, type) {
|
|
|
127
123
|
}
|
|
128
124
|
return obj;
|
|
129
125
|
};
|
|
130
|
-
var
|
|
131
|
-
|
|
132
|
-
{
|
|
133
|
-
element: react_1.default.createElement(layout_1.default, null),
|
|
134
|
-
path: '/',
|
|
135
|
-
children: (0, index_1.getChildrenRouteList)(routes_1.default, '')
|
|
136
|
-
}
|
|
137
|
-
];
|
|
138
|
-
var router = (routerType === 'hash' ? react_router_dom_1.createHashRouter : react_router_dom_1.createBrowserRouter)(routeList);
|
|
139
|
-
exports.history = {
|
|
126
|
+
var getHistory = function (router) {
|
|
127
|
+
return {
|
|
140
128
|
go: function (delta) {
|
|
141
129
|
router.navigate(delta);
|
|
142
130
|
},
|
|
@@ -178,6 +166,5 @@ var getRouter = function (routerType) {
|
|
|
178
166
|
return getLocation(router.state.location);
|
|
179
167
|
}
|
|
180
168
|
};
|
|
181
|
-
return router;
|
|
182
169
|
};
|
|
183
|
-
exports.
|
|
170
|
+
exports.getHistory = getHistory;
|
|
@@ -34,12 +34,15 @@ var loading_1 = __importDefault(require("../loading"));
|
|
|
34
34
|
var history_1 = require("./history");
|
|
35
35
|
var config_1 = require("./config");
|
|
36
36
|
require("../../global");
|
|
37
|
+
var layout_1 = __importDefault(require("../../layout"));
|
|
38
|
+
var routes_1 = __importDefault(require("./routes"));
|
|
37
39
|
var getChildrenRouteList = function (childrenRoutes, ancPathKey) {
|
|
38
40
|
return childrenRoutes === null || childrenRoutes === void 0 ? void 0 : childrenRoutes.map(function (item) {
|
|
39
41
|
var component = item.component, path = item.path, children = item.children, redirect = item.redirect;
|
|
40
42
|
var newAncPathKey = "".concat(ancPathKey, "-").concat(path);
|
|
41
43
|
return {
|
|
42
44
|
element: redirect ? (react_1.default.createElement(react_router_dom_1.Navigate, { to: redirect, replace: true })) : component ? (react_1.default.createElement(react_1.Suspense, { fallback: react_1.default.createElement(loading_1.default, null) }, (0, react_1.createElement)((0, react_1.lazy)(component)))) : (react_1.default.createElement(react_router_dom_1.Outlet, null)),
|
|
45
|
+
key: newAncPathKey,
|
|
43
46
|
path: path.startsWith('/') ? path.slice(1) : path,
|
|
44
47
|
children: (0, exports.getChildrenRouteList)(children, newAncPathKey)
|
|
45
48
|
};
|
|
@@ -47,12 +50,22 @@ var getChildrenRouteList = function (childrenRoutes, ancPathKey) {
|
|
|
47
50
|
};
|
|
48
51
|
exports.getChildrenRouteList = getChildrenRouteList;
|
|
49
52
|
var App = function () {
|
|
50
|
-
var
|
|
53
|
+
var routeList = [
|
|
54
|
+
{
|
|
55
|
+
element: react_1.default.createElement(layout_1.default, null),
|
|
56
|
+
path: '/',
|
|
57
|
+
children: (0, exports.getChildrenRouteList)(routes_1.default, '')
|
|
58
|
+
}
|
|
59
|
+
];
|
|
60
|
+
var router = (config_1.routerType === 'hash' ? react_router_dom_1.createHashRouter : react_router_dom_1.createBrowserRouter)(routeList);
|
|
51
61
|
if (config_1.routerBase && config_1.routerBase !== '/') {
|
|
52
62
|
if (config_1.routerType === 'browser' && window.location.pathname === '/') {
|
|
53
63
|
window.location.replace("".concat(config_1.routerBase));
|
|
54
64
|
}
|
|
55
65
|
}
|
|
66
|
+
(0, react_1.useLayoutEffect)(function () {
|
|
67
|
+
history_1.history = (0, history_1.getHistory)(router);
|
|
68
|
+
});
|
|
56
69
|
return react_1.default.createElement(react_router_dom_1.RouterProvider, { router: router, basename: config_1.routerBase });
|
|
57
70
|
};
|
|
58
71
|
var root = (0, client_1.createRoot)(document.getElementById('root'));
|