swico 0.5.0-beta8 → 0.5.0-beta9

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
1
  {
2
2
  "name": "swico",
3
- "version": "0.5.0-beta8",
3
+ "version": "0.5.0-beta9",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -7,6 +7,7 @@ exports.useLocation = void 0;
7
7
  var react_router_dom_1 = require("react-router-dom");
8
8
  var qs_1 = __importDefault(require("qs"));
9
9
  var history_1 = require("../react/history");
10
+ var routes_1 = require("../react/routes");
10
11
  var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
11
12
  var patternWithValuesParts = urlPatternWithValues.split('/');
12
13
  var patternWithParamsParts = urlPatternWithParams.split('/');
@@ -30,7 +31,7 @@ var useLocation = function () {
30
31
  var location = (0, react_router_dom_1.useLocation)();
31
32
  var params = (0, react_router_dom_1.useParams)();
32
33
  var search = location.search, hash = location.hash, pathname = location.pathname;
33
- var pathNameList = (0, history_1.getPathNameList)();
34
+ var pathNameList = (0, history_1.getPathNameList)(routes_1.routes);
34
35
  var name = (_a = pathNameList.find(function (item) { return (params && compareURLPatterns(pathname, item.path)) || item.path === pathname; })) === null || _a === void 0 ? void 0 : _a.name;
35
36
  var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
36
37
  return {
@@ -1,11 +1,12 @@
1
1
  import { ConfigRouterType } from '../../utils/config';
2
+ import { RoutesItemType } from './index';
2
3
  export { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom';
3
4
  export declare const formatAncPath: (ancPath: string) => string;
4
- export declare const getPathNameList: () => Array<{
5
+ export declare const getPathNameList: (routes: RoutesItemType[]) => Array<{
5
6
  path: string;
6
7
  name: string;
7
8
  }>;
8
- export declare const getHistory: (routerBase: ConfigRouterType['base'], routerType: ConfigRouterType['type']) => {
9
+ export declare const getHistory: (routerBase: ConfigRouterType['base'], routerType: ConfigRouterType['type'], routes: RoutesItemType[]) => {
9
10
  history: SwicoHistoryType;
10
11
  originalHistory: import("history").HashHistory;
11
12
  };
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getHistory = exports.getPathNameList = exports.formatAncPath = exports.HistoryRouter = void 0;
7
- var routes_1 = require("./routes");
8
7
  var qs_1 = __importDefault(require("qs"));
9
8
  var history_1 = require("history");
10
9
  var react_router_dom_1 = require("react-router-dom");
@@ -32,8 +31,7 @@ var formatAncPath = function (ancPath) {
32
31
  return newAncPath;
33
32
  };
34
33
  exports.formatAncPath = formatAncPath;
35
- var getPathNameList = function () {
36
- console.log('routes', routes_1.routes);
34
+ var getPathNameList = function (routes) {
37
35
  var list = [];
38
36
  var checkRouteItem = function (item, ancPath) {
39
37
  var path = item.path, name = item.name, children = item.children;
@@ -43,7 +41,8 @@ var getPathNameList = function () {
43
41
  children.some(function (item) { return checkRouteItem(item, newAncPath); });
44
42
  }
45
43
  };
46
- routes_1.routes.forEach(function (item) { return checkRouteItem(item, ''); });
44
+ console.log('rrr', routes);
45
+ routes.forEach(function (item) { return checkRouteItem(item, ''); });
47
46
  return list;
48
47
  };
49
48
  exports.getPathNameList = getPathNameList;
@@ -81,11 +80,11 @@ var getFormatHistoryOption = function (to, formatRouterBase, pathList, type) {
81
80
  }
82
81
  return obj;
83
82
  };
84
- var getHistory = function (routerBase, routerType) {
83
+ var getHistory = function (routerBase, routerType, routes) {
85
84
  var _a;
86
85
  var history;
87
86
  var originalHistory = (_a = (routerType === 'hash' ? history_1.createHashHistory : history_1.createBrowserHistory)) === null || _a === void 0 ? void 0 : _a();
88
- var pathNameList = (0, exports.getPathNameList)();
87
+ var pathNameList = (0, exports.getPathNameList)(routes);
89
88
  var lastIndexBase = routerBase[routerBase.length - 1];
90
89
  var formatRouterBase = lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
91
90
  history = {
@@ -43,7 +43,7 @@ var renderChildrenRouteList = function (childrenRoutes, ancPathKey) {
43
43
  });
44
44
  };
45
45
  var App = function () {
46
- var _a = (0, history_1.getHistory)(config_1.routerBase, config_1.routerType), history = _a.history, originalHistory = _a.originalHistory;
46
+ var _a = (0, history_1.getHistory)(config_1.routerBase, config_1.routerType, routes_1.routes), history = _a.history, originalHistory = _a.originalHistory;
47
47
  if (config_1.routerBase && config_1.routerBase !== '/') {
48
48
  if (config_1.routerType === 'browser' && window.location.pathname === '/') {
49
49
  window.location.replace("".concat(config_1.routerBase));