@tarojs/router 3.5.0-alpha.1 → 3.5.0-alpha.10

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
@@ -1,12 +1,22 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { parsePath } from 'history';
2
11
  import stacks from './router/stack';
3
12
  import { history, prependBasename } from './history';
4
13
  import { routesAlias, addLeadingSlash } from './utils';
5
14
  import { RouterConfig } from './router';
6
15
  function processNavigateUrl(option) {
16
+ var _a;
7
17
  const pathPieces = parsePath(option.url);
8
18
  // 处理相对路径
9
- if (pathPieces.pathname?.includes('./')) {
19
+ if ((_a = pathPieces.pathname) === null || _a === void 0 ? void 0 : _a.includes('./')) {
10
20
  const parts = routesAlias.getOrigin(history.location.pathname).split('/');
11
21
  parts.pop();
12
22
  pathPieces.pathname.split('/').forEach((item) => {
@@ -26,42 +36,44 @@ function processNavigateUrl(option) {
26
36
  pathPieces.search = '';
27
37
  return pathPieces;
28
38
  }
29
- async function navigate(option, method) {
30
- return new Promise((resolve, reject) => {
31
- const { success, complete, fail } = option;
32
- const unListen = history.listen(() => {
33
- const res = { errMsg: `${method}:ok` };
34
- success?.(res);
35
- complete?.(res);
36
- resolve(res);
37
- unListen();
38
- });
39
- try {
40
- if ('url' in option) {
41
- const pathPieces = processNavigateUrl(option);
42
- const state = { timestamp: Date.now() };
43
- if (method === 'navigateTo') {
44
- history.push(pathPieces, state);
39
+ function navigate(option, method) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ return new Promise((resolve, reject) => {
42
+ const { success, complete, fail } = option;
43
+ const unListen = history.listen(() => {
44
+ const res = { errMsg: `${method}:ok` };
45
+ success === null || success === void 0 ? void 0 : success(res);
46
+ complete === null || complete === void 0 ? void 0 : complete(res);
47
+ resolve(res);
48
+ unListen();
49
+ });
50
+ try {
51
+ if ('url' in option) {
52
+ const pathPieces = processNavigateUrl(option);
53
+ const state = { timestamp: Date.now() };
54
+ if (method === 'navigateTo') {
55
+ history.push(pathPieces, state);
56
+ }
57
+ else if (method === 'redirectTo' || method === 'switchTab') {
58
+ history.replace(pathPieces, state);
59
+ }
60
+ else if (method === 'reLaunch') {
61
+ stacks.delta = stacks.length;
62
+ history.replace(pathPieces, state);
63
+ }
45
64
  }
46
- else if (method === 'redirectTo' || method === 'switchTab') {
47
- history.replace(pathPieces, state);
48
- }
49
- else if (method === 'reLaunch') {
50
- stacks.delta = stacks.length;
51
- history.replace(pathPieces, state);
65
+ else if (method === 'navigateBack') {
66
+ stacks.delta = option.delta;
67
+ history.go(-option.delta);
52
68
  }
53
69
  }
54
- else if (method === 'navigateBack') {
55
- stacks.delta = option.delta;
56
- history.go(-option.delta);
70
+ catch (error) {
71
+ const res = { errMsg: `${method}:fail ${error.message || error}` };
72
+ fail === null || fail === void 0 ? void 0 : fail(res);
73
+ complete === null || complete === void 0 ? void 0 : complete(res);
74
+ reject(res);
57
75
  }
58
- }
59
- catch (error) {
60
- const res = { errMsg: `${method}:fail ${error.message || error}` };
61
- fail?.(res);
62
- complete?.(res);
63
- reject(res);
64
- }
76
+ });
65
77
  });
66
78
  }
67
79
  export function navigateTo(option) {
@@ -87,5 +99,5 @@ export function getCurrentPages() {
87
99
  console.warn('多页面路由模式不支持使用 getCurrentPages 方法!');
88
100
  }
89
101
  const pages = stacks.get();
90
- return pages.map(e => ({ ...e, route: e.path || '' }));
102
+ return pages.map(e => (Object.assign(Object.assign({}, e), { route: e.path || '' })));
91
103
  }
package/dist/history.js CHANGED
@@ -3,7 +3,12 @@ import { RouterConfig } from './router';
3
3
  export let history;
4
4
  let basename = '/';
5
5
  class MpaHistory {
6
- action;
6
+ constructor() {
7
+ this.back = window.history.back;
8
+ this.forward = window.history.forward;
9
+ this.pushState = this.eventState('pushState');
10
+ this.replaceState = this.eventState('replaceState');
11
+ }
7
12
  get location() {
8
13
  return {
9
14
  pathname: window.location.pathname,
@@ -40,8 +45,6 @@ class MpaHistory {
40
45
  go(delta) {
41
46
  window.history.go(delta);
42
47
  }
43
- back = window.history.back;
44
- forward = window.history.forward;
45
48
  listen(listener) {
46
49
  function callback(e) {
47
50
  if (e.action === 'pushState') {
@@ -63,8 +66,6 @@ class MpaHistory {
63
66
  block(_blocker) {
64
67
  throw new Error('Method not implemented.');
65
68
  }
66
- pushState = this.eventState('pushState');
67
- replaceState = this.eventState('replaceState');
68
69
  eventState(action) {
69
70
  return (data, unused, url) => {
70
71
  const wrapper = window.history[action](data, unused, url);