@ray-js/router-mp 0.10.2 → 0.20.0-beta.0

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/lib/Router.d.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import { Router as TRouter, RouteOptions } from '@ray-js/types';
2
2
  import { RouterScheduler } from './RouterScheduler';
3
3
  export declare class Router implements TRouter {
4
+ private urlPrefix;
5
+ /**
6
+ * setUrlPrefix
7
+ */
8
+ setUrlPrefix(prefix: string): void;
4
9
  scheduler: RouterScheduler;
5
10
  /**
6
11
  * 标准化路由路径,将 web 标准的地址栏转化到 小程序地址
package/lib/Router.js CHANGED
@@ -7,6 +7,10 @@ import "core-js/modules/es.promise.js";
7
7
  import "core-js/modules/es.array.slice.js";
8
8
  import "core-js/modules/es.regexp.exec.js";
9
9
  import "core-js/modules/es.string.replace.js";
10
+ import "core-js/modules/es.regexp.constructor.js";
11
+ import "core-js/modules/es.regexp.dot-all.js";
12
+ import "core-js/modules/es.regexp.sticky.js";
13
+ import "core-js/modules/es.regexp.to-string.js";
10
14
  import { url } from '@ray-js/library';
11
15
  import { navigateBack, navigateTo, reLaunch, switchTab, redirectTo, getLaunchOptionsSync } from '@ray-js/api';
12
16
  import { isThing } from '@ray-js/env';
@@ -33,10 +37,21 @@ export var Router = /*#__PURE__*/function () {
33
37
  function Router() {
34
38
  _classCallCheck(this, Router);
35
39
 
40
+ _defineProperty(this, "urlPrefix", '');
41
+
36
42
  _defineProperty(this, "scheduler", new RouterScheduler());
37
43
  }
38
44
 
39
45
  _createClass(Router, [{
46
+ key: "setUrlPrefix",
47
+ value:
48
+ /**
49
+ * setUrlPrefix
50
+ */
51
+ function setUrlPrefix(prefix) {
52
+ this.urlPrefix = prefix;
53
+ }
54
+ }, {
40
55
  key: "normalizeRoute",
41
56
  value:
42
57
  /**
@@ -53,6 +68,11 @@ export var Router = /*#__PURE__*/function () {
53
68
 
54
69
  if (!matchedPage) {
55
70
  return Promise.reject(undefined);
71
+ } // 作为其他小程序时不能作为tabBar
72
+
73
+
74
+ if (this.urlPrefix) {
75
+ matchedPage.isTabBar = false;
56
76
  }
57
77
 
58
78
  var finalPath = matchedPage.path; // FIXME: tabBar.list里的页面不能有query,也不能有hash
@@ -70,11 +90,19 @@ export var Router = /*#__PURE__*/function () {
70
90
  /**
71
91
  * 坑点之一
72
92
  * 微信小程序: app.json 里的页面配置不能以`/`开头,wx.navigatorTo 却需要
73
- * 涂药小程序: 都不能以`/`开头
93
+ * 涂鸦小程序: 都不能以`/`开头
74
94
  */
75
95
 
76
96
 
77
- matchedPage.path = isThing ? finalPath.replace(/^\//, '') : finalPath;
97
+ if (this.urlPrefix) {
98
+ finalPath = ('/' + this.urlPrefix + '/' + finalPath).replace(/\/+/g, '/');
99
+ }
100
+
101
+ if (isThing) {
102
+ finalPath = finalPath.replace(/^\//, '');
103
+ }
104
+
105
+ matchedPage.path = finalPath;
78
106
  return Promise.resolve(matchedPage);
79
107
  }
80
108
  }, {
@@ -142,7 +170,9 @@ export var Router = /*#__PURE__*/function () {
142
170
  key: "href",
143
171
  get: function get() {
144
172
  var page = currentPage();
145
- var path = url.params("/".concat(page.route), page.options);
173
+ var reg = RegExp('^' + this.urlPrefix + '/');
174
+ var r = page.route.replace(reg, '');
175
+ var path = url.params("/".concat(r), page.options);
146
176
 
147
177
  var _url$parse2 = url.parse(path),
148
178
  pathname = _url$parse2.pathname,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/router-mp",
3
- "version": "0.10.2",
3
+ "version": "0.20.0-beta.0",
4
4
  "description": "Ray Core",
5
5
  "keywords": [
6
6
  "ray"
@@ -20,16 +20,16 @@
20
20
  "watch": "tsc -p ./tsconfig.build.json --module esnext --outDir lib --watch"
21
21
  },
22
22
  "dependencies": {
23
- "@ray-js/api": "^0.10.2",
24
- "@ray-js/env": "^0.10.2",
25
- "@ray-js/library": "^0.10.2",
26
- "@ray-js/types": "^0.10.2",
23
+ "@ray-js/api": "^0.20.0-beta.0",
24
+ "@ray-js/env": "^0.20.0-beta.0",
25
+ "@ray-js/library": "^0.20.0-beta.0",
26
+ "@ray-js/types": "^0.20.0-beta.0",
27
27
  "@react-navigation/core": "^6.1.0",
28
28
  "path-to-regexp": "^6.2.0",
29
29
  "slash": "^5.0.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@ray-js/cli": "^0.10.2"
32
+ "@ray-js/cli": "^0.20.0-beta.0"
33
33
  },
34
34
  "maintainers": [
35
35
  {
@@ -37,6 +37,6 @@
37
37
  "email": "tuyafe@tuya.com"
38
38
  }
39
39
  ],
40
- "gitHead": "05f65fee00b3174d78bd9201df6eb8cedfcfe03f",
40
+ "gitHead": "5f36d50a16fb4a25a16b04d35b211af44b677dce",
41
41
  "repository": {}
42
42
  }