@tarojs/router 3.6.29 → 3.6.30

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/dist/api.js CHANGED
@@ -16,13 +16,14 @@ function processNavigateUrl(option) {
16
16
  const parts = routesAlias.getOrigin(history.location.pathname).split('/');
17
17
  parts.pop();
18
18
  pathPieces.pathname.split('/').forEach((item) => {
19
- if (item === '.') {
19
+ if (item === '.')
20
20
  return;
21
- }
22
21
  item === '..' ? parts.pop() : parts.push(item);
23
22
  });
24
23
  pathPieces.pathname = parts.join('/');
25
24
  }
25
+ // 确保是 / 开头的路径
26
+ pathPieces.pathname = addLeadingSlash(pathPieces.pathname);
26
27
  // 处理自定义路由
27
28
  pathPieces.pathname = routesAlias.getAlias(addLeadingSlash(pathPieces.pathname));
28
29
  // 处理 basename
@@ -50,17 +51,6 @@ function navigate(option, method) {
50
51
  });
51
52
  try {
52
53
  if ('url' in option) {
53
- if (!RouterConfig.isPage(addLeadingSlash(option.url))) {
54
- const res = { errMsg: `${method}:fail page ${option.url} is not found` };
55
- fail === null || fail === void 0 ? void 0 : fail(res);
56
- complete === null || complete === void 0 ? void 0 : complete(res);
57
- if (fail || complete) {
58
- return resolve(res);
59
- }
60
- else {
61
- return reject(res);
62
- }
63
- }
64
54
  const pathPieces = processNavigateUrl(option);
65
55
  const state = { timestamp: Date.now() };
66
56
  if (method === 'navigateTo') {
package/dist/index.cjs.js CHANGED
@@ -535,13 +535,14 @@ function processNavigateUrl(option) {
535
535
  const parts = routesAlias.getOrigin(exports.history.location.pathname).split('/');
536
536
  parts.pop();
537
537
  pathPieces.pathname.split('/').forEach((item) => {
538
- if (item === '.') {
538
+ if (item === '.')
539
539
  return;
540
- }
541
540
  item === '..' ? parts.pop() : parts.push(item);
542
541
  });
543
542
  pathPieces.pathname = parts.join('/');
544
543
  }
544
+ // 确保是 / 开头的路径
545
+ pathPieces.pathname = runtime.addLeadingSlash(pathPieces.pathname);
545
546
  // 处理自定义路由
546
547
  pathPieces.pathname = routesAlias.getAlias(runtime.addLeadingSlash(pathPieces.pathname));
547
548
  // 处理 basename
@@ -569,17 +570,6 @@ function navigate(option, method) {
569
570
  });
570
571
  try {
571
572
  if ('url' in option) {
572
- if (!RouterConfig.isPage(runtime.addLeadingSlash(option.url))) {
573
- const res = { errMsg: `${method}:fail page ${option.url} is not found` };
574
- fail === null || fail === void 0 ? void 0 : fail(res);
575
- complete === null || complete === void 0 ? void 0 : complete(res);
576
- if (fail || complete) {
577
- return resolve(res);
578
- }
579
- else {
580
- return reject(res);
581
- }
582
- }
583
573
  const pathPieces = processNavigateUrl(option);
584
574
  const state = { timestamp: Date.now() };
585
575
  if (method === 'navigateTo') {
@@ -975,7 +965,7 @@ class NavigationBarHandler {
975
965
  this.setNavigationLoading();
976
966
  }
977
967
  setCacheValue() {
978
- const currentPage = this.pageContext.currentPage;
968
+ const currentPage = this.pageContext.originPathname;
979
969
  if (typeof this.cache[currentPage] !== 'object') {
980
970
  this.cache[currentPage] = {};
981
971
  }
@@ -1006,7 +996,7 @@ class NavigationBarHandler {
1006
996
  var _a;
1007
997
  if (!this.navigationBarElement)
1008
998
  return;
1009
- const currentPage = this.pageContext.currentPage;
999
+ const currentPage = this.pageContext.originPathname;
1010
1000
  let isShow;
1011
1001
  if (typeof show === 'boolean') {
1012
1002
  isShow = show;
@@ -1031,7 +1021,7 @@ class NavigationBarHandler {
1031
1021
  var _a, _b, _c;
1032
1022
  if (!this.navigationBarElement)
1033
1023
  return;
1034
- const currentPage = this.pageContext.currentPage;
1024
+ const currentPage = this.pageContext.originPathname;
1035
1025
  let color;
1036
1026
  if (typeof backgroundColor === 'string') {
1037
1027
  color = backgroundColor;
@@ -1055,7 +1045,7 @@ class NavigationBarHandler {
1055
1045
  var _a, _b, _c;
1056
1046
  if (!this.navigationBarElement)
1057
1047
  return;
1058
- const currentPage = this.pageContext.currentPage;
1048
+ const currentPage = this.pageContext.originPathname;
1059
1049
  let color;
1060
1050
  if (typeof fontColor === 'string') {
1061
1051
  color = fontColor;
@@ -1077,7 +1067,7 @@ class NavigationBarHandler {
1077
1067
  }
1078
1068
  setTitle(title) {
1079
1069
  var _a, _b, _c;
1080
- const currentPage = this.pageContext.currentPage;
1070
+ const currentPage = this.pageContext.originPathname;
1081
1071
  let proceedTitle;
1082
1072
  if (typeof title === 'string') {
1083
1073
  proceedTitle = title;
@@ -1192,14 +1182,14 @@ class PageHandler {
1192
1182
  }
1193
1183
  set pathname(p) { this.router.pathname = p; }
1194
1184
  get pathname() { return this.router.pathname; }
1185
+ // Note: 把 pathname 转换为原始路径,主要是处理 customRoutes 和 basename
1186
+ get originPathname() { return routesAlias.getOrigin(runtime.addLeadingSlash(runtime.stripBasename(this.pathname, this.basename))); }
1195
1187
  get basename() { return this.router.basename || ''; }
1196
1188
  get pageConfig() {
1197
- const routePath = runtime.addLeadingSlash(runtime.stripBasename(this.pathname, this.basename));
1198
1189
  const homePage = runtime.addLeadingSlash(this.homePage);
1199
1190
  return this.routes.find(r => {
1200
- var _a;
1201
1191
  const pagePath = runtime.addLeadingSlash(r.path);
1202
- return [pagePath, homePage].includes(routePath) || ((_a = routesAlias.getConfig(pagePath)) === null || _a === void 0 ? void 0 : _a.includes(routePath));
1192
+ return [pagePath, homePage].includes(this.originPathname);
1203
1193
  });
1204
1194
  }
1205
1195
  isTabBar(pathname) {
package/dist/index.esm.js CHANGED
@@ -534,13 +534,14 @@ function processNavigateUrl(option) {
534
534
  const parts = routesAlias.getOrigin(history.location.pathname).split('/');
535
535
  parts.pop();
536
536
  pathPieces.pathname.split('/').forEach((item) => {
537
- if (item === '.') {
537
+ if (item === '.')
538
538
  return;
539
- }
540
539
  item === '..' ? parts.pop() : parts.push(item);
541
540
  });
542
541
  pathPieces.pathname = parts.join('/');
543
542
  }
543
+ // 确保是 / 开头的路径
544
+ pathPieces.pathname = addLeadingSlash(pathPieces.pathname);
544
545
  // 处理自定义路由
545
546
  pathPieces.pathname = routesAlias.getAlias(addLeadingSlash(pathPieces.pathname));
546
547
  // 处理 basename
@@ -568,17 +569,6 @@ function navigate(option, method) {
568
569
  });
569
570
  try {
570
571
  if ('url' in option) {
571
- if (!RouterConfig.isPage(addLeadingSlash(option.url))) {
572
- const res = { errMsg: `${method}:fail page ${option.url} is not found` };
573
- fail === null || fail === void 0 ? void 0 : fail(res);
574
- complete === null || complete === void 0 ? void 0 : complete(res);
575
- if (fail || complete) {
576
- return resolve(res);
577
- }
578
- else {
579
- return reject(res);
580
- }
581
- }
582
572
  const pathPieces = processNavigateUrl(option);
583
573
  const state = { timestamp: Date.now() };
584
574
  if (method === 'navigateTo') {
@@ -974,7 +964,7 @@ class NavigationBarHandler {
974
964
  this.setNavigationLoading();
975
965
  }
976
966
  setCacheValue() {
977
- const currentPage = this.pageContext.currentPage;
967
+ const currentPage = this.pageContext.originPathname;
978
968
  if (typeof this.cache[currentPage] !== 'object') {
979
969
  this.cache[currentPage] = {};
980
970
  }
@@ -1005,7 +995,7 @@ class NavigationBarHandler {
1005
995
  var _a;
1006
996
  if (!this.navigationBarElement)
1007
997
  return;
1008
- const currentPage = this.pageContext.currentPage;
998
+ const currentPage = this.pageContext.originPathname;
1009
999
  let isShow;
1010
1000
  if (typeof show === 'boolean') {
1011
1001
  isShow = show;
@@ -1030,7 +1020,7 @@ class NavigationBarHandler {
1030
1020
  var _a, _b, _c;
1031
1021
  if (!this.navigationBarElement)
1032
1022
  return;
1033
- const currentPage = this.pageContext.currentPage;
1023
+ const currentPage = this.pageContext.originPathname;
1034
1024
  let color;
1035
1025
  if (typeof backgroundColor === 'string') {
1036
1026
  color = backgroundColor;
@@ -1054,7 +1044,7 @@ class NavigationBarHandler {
1054
1044
  var _a, _b, _c;
1055
1045
  if (!this.navigationBarElement)
1056
1046
  return;
1057
- const currentPage = this.pageContext.currentPage;
1047
+ const currentPage = this.pageContext.originPathname;
1058
1048
  let color;
1059
1049
  if (typeof fontColor === 'string') {
1060
1050
  color = fontColor;
@@ -1076,7 +1066,7 @@ class NavigationBarHandler {
1076
1066
  }
1077
1067
  setTitle(title) {
1078
1068
  var _a, _b, _c;
1079
- const currentPage = this.pageContext.currentPage;
1069
+ const currentPage = this.pageContext.originPathname;
1080
1070
  let proceedTitle;
1081
1071
  if (typeof title === 'string') {
1082
1072
  proceedTitle = title;
@@ -1191,14 +1181,14 @@ class PageHandler {
1191
1181
  }
1192
1182
  set pathname(p) { this.router.pathname = p; }
1193
1183
  get pathname() { return this.router.pathname; }
1184
+ // Note: 把 pathname 转换为原始路径,主要是处理 customRoutes 和 basename
1185
+ get originPathname() { return routesAlias.getOrigin(addLeadingSlash(stripBasename(this.pathname, this.basename))); }
1194
1186
  get basename() { return this.router.basename || ''; }
1195
1187
  get pageConfig() {
1196
- const routePath = addLeadingSlash(stripBasename(this.pathname, this.basename));
1197
1188
  const homePage = addLeadingSlash(this.homePage);
1198
1189
  return this.routes.find(r => {
1199
- var _a;
1200
1190
  const pagePath = addLeadingSlash(r.path);
1201
- return [pagePath, homePage].includes(routePath) || ((_a = routesAlias.getConfig(pagePath)) === null || _a === void 0 ? void 0 : _a.includes(routePath));
1191
+ return [pagePath, homePage].includes(this.originPathname);
1202
1192
  });
1203
1193
  }
1204
1194
  isTabBar(pathname) {
@@ -73,7 +73,7 @@ class NavigationBarHandler {
73
73
  this.setNavigationLoading();
74
74
  }
75
75
  setCacheValue() {
76
- const currentPage = this.pageContext.currentPage;
76
+ const currentPage = this.pageContext.originPathname;
77
77
  if (typeof this.cache[currentPage] !== 'object') {
78
78
  this.cache[currentPage] = {};
79
79
  }
@@ -104,7 +104,7 @@ class NavigationBarHandler {
104
104
  var _a;
105
105
  if (!this.navigationBarElement)
106
106
  return;
107
- const currentPage = this.pageContext.currentPage;
107
+ const currentPage = this.pageContext.originPathname;
108
108
  let isShow;
109
109
  if (typeof show === 'boolean') {
110
110
  isShow = show;
@@ -129,7 +129,7 @@ class NavigationBarHandler {
129
129
  var _a, _b, _c;
130
130
  if (!this.navigationBarElement)
131
131
  return;
132
- const currentPage = this.pageContext.currentPage;
132
+ const currentPage = this.pageContext.originPathname;
133
133
  let color;
134
134
  if (typeof backgroundColor === 'string') {
135
135
  color = backgroundColor;
@@ -153,7 +153,7 @@ class NavigationBarHandler {
153
153
  var _a, _b, _c;
154
154
  if (!this.navigationBarElement)
155
155
  return;
156
- const currentPage = this.pageContext.currentPage;
156
+ const currentPage = this.pageContext.originPathname;
157
157
  let color;
158
158
  if (typeof fontColor === 'string') {
159
159
  color = fontColor;
@@ -175,7 +175,7 @@ class NavigationBarHandler {
175
175
  }
176
176
  setTitle(title) {
177
177
  var _a, _b, _c;
178
- const currentPage = this.pageContext.currentPage;
178
+ const currentPage = this.pageContext.originPathname;
179
179
  let proceedTitle;
180
180
  if (typeof title === 'string') {
181
181
  proceedTitle = title;
@@ -28,6 +28,7 @@ declare class PageHandler {
28
28
  get animationDuration(): number;
29
29
  set pathname(p: string);
30
30
  get pathname(): string;
31
+ get originPathname(): string;
31
32
  get basename(): string;
32
33
  get pageConfig(): Route | undefined;
33
34
  isTabBar(pathname: string): boolean;
@@ -49,14 +49,14 @@ class PageHandler {
49
49
  }
50
50
  set pathname(p) { this.router.pathname = p; }
51
51
  get pathname() { return this.router.pathname; }
52
+ // Note: 把 pathname 转换为原始路径,主要是处理 customRoutes 和 basename
53
+ get originPathname() { return routesAlias.getOrigin(addLeadingSlash(stripBasename(this.pathname, this.basename))); }
52
54
  get basename() { return this.router.basename || ''; }
53
55
  get pageConfig() {
54
- const routePath = addLeadingSlash(stripBasename(this.pathname, this.basename));
55
56
  const homePage = addLeadingSlash(this.homePage);
56
57
  return this.routes.find(r => {
57
- var _a;
58
58
  const pagePath = addLeadingSlash(r.path);
59
- return [pagePath, homePage].includes(routePath) || ((_a = routesAlias.getConfig(pagePath)) === null || _a === void 0 ? void 0 : _a.includes(routePath));
59
+ return [pagePath, homePage].includes(this.originPathname);
60
60
  });
61
61
  }
62
62
  isTabBar(pathname) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/router",
3
- "version": "3.6.29",
3
+ "version": "3.6.30",
4
4
  "description": "Taro-router",
5
5
  "browser": "dist/index.js",
6
6
  "main:h5": "dist/index.esm.js",
@@ -44,14 +44,14 @@
44
44
  "rollup-plugin-ts": "^3.0.2",
45
45
  "ts-jest": "^29.0.5",
46
46
  "typescript": "^4.7.4",
47
- "@tarojs/runtime": "3.6.29",
48
- "@tarojs/taro": "3.6.29",
49
- "@tarojs/shared": "3.6.29"
47
+ "@tarojs/runtime": "3.6.30",
48
+ "@tarojs/shared": "3.6.30",
49
+ "@tarojs/taro": "3.6.30"
50
50
  },
51
51
  "peerDependencies": {
52
- "@tarojs/runtime": "3.6.29",
53
- "@tarojs/taro": "3.6.29",
54
- "@tarojs/shared": "3.6.29"
52
+ "@tarojs/runtime": "3.6.30",
53
+ "@tarojs/shared": "3.6.30",
54
+ "@tarojs/taro": "3.6.30"
55
55
  },
56
56
  "scripts": {
57
57
  "prebuild": "pnpm run clean",