@deppon/deppon-router 2.3.1 → 2.3.3

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.
Files changed (2) hide show
  1. package/es/utils.js +50 -1
  2. package/package.json +1 -1
package/es/utils.js CHANGED
@@ -184,6 +184,38 @@ function mergeViewTabConfig(defaultConfig, userConfig) {
184
184
  uumsFunction: userConfig.uumsFunction || defaultConfig.uumsFunction
185
185
  });
186
186
  }
187
+
188
+ /** path 是否为 http(s) 绝对地址(不经 Vue Router 解析,避免被拼到当前站点 base 后) */
189
+ function isHttpAbsolutePath(path) {
190
+ return typeof path === 'string' && /^https?:\/\//i.test(path.trim());
191
+ }
192
+
193
+ /**
194
+ * 将 { path: 绝对外链, query } 合并为完整 URL
195
+ * @param {{ path: string, query?: Record<string, unknown> }} location
196
+ */
197
+ function mergeExternalPathAndQuery(location) {
198
+ var raw = location.path.trim();
199
+ if (!location.query || _typeof(location.query) !== 'object' || Object.keys(location.query).length === 0) {
200
+ return raw;
201
+ }
202
+ try {
203
+ var u = new URL(raw);
204
+ for (var _i = 0, _Object$entries = Object.entries(location.query); _i < _Object$entries.length; _i++) {
205
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
206
+ k = _Object$entries$_i[0],
207
+ v = _Object$entries$_i[1];
208
+ if (v === undefined || v === null) continue;
209
+ var val = Array.isArray(v) ? v.map(String).join(',') : String(v);
210
+ if (!u.searchParams.has(k)) {
211
+ u.searchParams.append(k, val);
212
+ }
213
+ }
214
+ return u.href;
215
+ } catch (error) {
216
+ return raw;
217
+ }
218
+ }
187
219
  function createRouterUtils(router) {
188
220
  var defaultViewTab = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
189
221
  // 保存原始的 push 方法
@@ -198,7 +230,7 @@ function createRouterUtils(router) {
198
230
  if (typeof location === 'string') {
199
231
  var _router$options$histo;
200
232
  // 字符串路径
201
- if (location.startsWith('http')) {
233
+ if (/^https?:\/\//i.test(location.trim())) {
202
234
  return location;
203
235
  }
204
236
  // 处理 hash 模式
@@ -210,6 +242,11 @@ function createRouterUtils(router) {
210
242
  return "".concat(window.location.origin).concat(location.startsWith('/') ? location : "/".concat(location));
211
243
  }
212
244
 
245
+ // path 为完整 http(s) 地址时,不能使用 router.resolve(会被当作站内相对 path)
246
+ if (location && _typeof(location) === 'object' && isHttpAbsolutePath(location.path)) {
247
+ return mergeExternalPathAndQuery(location);
248
+ }
249
+
213
250
  // 使用 router.resolve 来正确解析路由(包括 params 和 query)
214
251
  var resolved = router.resolve(location);
215
252
  var url = resolved.href;
@@ -549,6 +586,18 @@ function createRouterUtils(router) {
549
586
  }
550
587
  }
551
588
 
589
+ // 外链:path 为 http(s) 完整地址时不能交给 Vue Router,否则会拼成 当前站点 + 外链
590
+ if (cleanLocation && _typeof(cleanLocation) === 'object' && isHttpAbsolutePath(cleanLocation.path)) {
591
+ var externalUrl = locationToUrl(cleanLocation);
592
+ if (typeof window !== 'undefined') {
593
+ window.location.assign(externalUrl);
594
+ }
595
+ if (onComplete) {
596
+ onComplete();
597
+ }
598
+ return Promise.resolve();
599
+ }
600
+
552
601
  // 降级处理:使用普通 push(使用清理后的 location)
553
602
  return this.safePush(cleanLocation, onComplete, onAbort);
554
603
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deppon/deppon-router",
3
- "version": "2.3.1",
3
+ "version": "2.3.3",
4
4
  "description": "Vue Router 4 wrapper package",
5
5
  "license": "MIT",
6
6
  "homepage": "",