@pisell/core 1.0.25 → 1.0.26

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.
@@ -55,10 +55,27 @@ export var MenuManager = /*#__PURE__*/function () {
55
55
  }, {
56
56
  key: "findMenuItemByPath",
57
57
  value: function findMenuItemByPath(items, path) {
58
+ // 首先尝试精确匹配
58
59
  var menu = this.menuMaps[path];
59
60
  if (menu) {
60
61
  return menu;
61
62
  }
63
+
64
+ // 提取路径的主要部分(去掉查询参数和hash)
65
+ var getPathname = function getPathname(url) {
66
+ var questionMarkIndex = url.indexOf('?');
67
+ var hashIndex = url.indexOf('#');
68
+ var endIndex = url.length;
69
+ if (questionMarkIndex !== -1 && hashIndex !== -1) {
70
+ endIndex = Math.min(questionMarkIndex, hashIndex);
71
+ } else if (questionMarkIndex !== -1) {
72
+ endIndex = questionMarkIndex;
73
+ } else if (hashIndex !== -1) {
74
+ endIndex = hashIndex;
75
+ }
76
+ return url.substring(0, endIndex);
77
+ };
78
+ var inputPathname = getPathname(path);
62
79
  var _iterator = _createForOfIteratorHelper(items),
63
80
  _step;
64
81
  try {
@@ -69,6 +86,12 @@ export var MenuManager = /*#__PURE__*/function () {
69
86
  if (item !== null && item !== void 0 && (_item$path = item.path) !== null && _item$path !== void 0 && _item$path.includes('/:') && path.startsWith(item.path.split('/:')[0])) {
70
87
  return item;
71
88
  }
89
+
90
+ // 比较路径的主要部分(忽略查询参数)
91
+ var itemPathname = getPathname(item.path);
92
+ if (itemPathname === inputPathname) {
93
+ return item;
94
+ }
72
95
  if (item.children) {
73
96
  var found = this.findMenuItemByPath(item.children, path);
74
97
  if (found) return found;
@@ -62,10 +62,28 @@ var MenuManager = class {
62
62
  if (menu) {
63
63
  return menu;
64
64
  }
65
+ const getPathname = (url) => {
66
+ const questionMarkIndex = url.indexOf("?");
67
+ const hashIndex = url.indexOf("#");
68
+ let endIndex = url.length;
69
+ if (questionMarkIndex !== -1 && hashIndex !== -1) {
70
+ endIndex = Math.min(questionMarkIndex, hashIndex);
71
+ } else if (questionMarkIndex !== -1) {
72
+ endIndex = questionMarkIndex;
73
+ } else if (hashIndex !== -1) {
74
+ endIndex = hashIndex;
75
+ }
76
+ return url.substring(0, endIndex);
77
+ };
78
+ const inputPathname = getPathname(path);
65
79
  for (const item of items) {
66
80
  if (((_a = item == null ? void 0 : item.path) == null ? void 0 : _a.includes("/:")) && path.startsWith(item.path.split("/:")[0])) {
67
81
  return item;
68
82
  }
83
+ const itemPathname = getPathname(item.path);
84
+ if (itemPathname === inputPathname) {
85
+ return item;
86
+ }
69
87
  if (item.children) {
70
88
  const found = this.findMenuItemByPath(item.children, path);
71
89
  if (found) return found;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/core",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "sideEffects": false,
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",