@rxdrag/website-lib-core 0.0.131 → 0.0.133

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": "@rxdrag/website-lib-core",
3
- "version": "0.0.131",
3
+ "version": "0.0.133",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.ts"
@@ -23,8 +23,8 @@
23
23
  "@types/react-dom": "^19.1.0",
24
24
  "eslint": "^9.39.2",
25
25
  "typescript": "^5",
26
- "@rxdrag/eslint-config-custom": "0.2.13",
27
26
  "@rxdrag/tiptap-preview": "0.0.3",
27
+ "@rxdrag/eslint-config-custom": "0.2.13",
28
28
  "@rxdrag/tsconfig": "0.2.1"
29
29
  },
30
30
  "dependencies": {
@@ -37,7 +37,7 @@
37
37
  "@rxdrag/rxcms-models": "0.3.111"
38
38
  },
39
39
  "peerDependencies": {
40
- "astro": "^5.16.6",
40
+ "astro": "^6.1.1",
41
41
  "react": "^18.0.0 || ^19.0.0",
42
42
  "react-dom": "^18.0.0 || ^19.0.0"
43
43
  },
@@ -1,3 +1,10 @@
1
+ // 判断路径是否为根路径(/ 或 /zh/ 等语言前缀根路径)
2
+ const isRootPath = (path: string): boolean => {
3
+ if (path === "/") return true;
4
+ // 匹配 /xx/ 或 /xx-xx/ 格式的语言前缀根路径
5
+ return /^\/[a-z]{2}(-[a-z]{2})?\/?$/.test(path);
6
+ };
7
+
1
8
  export const initLinks = () => {
2
9
  // 获取当前URL的路径部分(去除域名)
3
10
  const currentPath = window.location.pathname;
@@ -15,11 +22,14 @@ export const initLinks = () => {
15
22
  anchorLink.dataset.activedPath === "true"
16
23
  ? linkUrl?.pathname
17
24
  : anchorLink.dataset.activedPath;
18
- // 检查当前路径是否与链接路径匹配或是其子路径
19
- if (
20
- currentPath === linkPath ||
21
- (linkPath !== "/" && linkPath && currentPath.startsWith(linkPath))
22
- ) {
25
+
26
+ // 根路径使用精确匹配,其他路径使用前缀匹配
27
+ const isRoot = linkPath ? isRootPath(linkPath) : false;
28
+ const isMatch = isRoot
29
+ ? currentPath === linkPath || currentPath === linkPath?.replace(/\/$/, "")
30
+ : currentPath === linkPath || (linkPath && currentPath.startsWith(linkPath));
31
+
32
+ if (isMatch) {
23
33
  anchorLink.classList.add("actived");
24
34
  } else {
25
35
  anchorLink.classList.remove("actived");