@ray-js/router-mp 1.6.31 → 1.7.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,4 +1,4 @@
1
- import { Router as TRouter, RouteOptions } from '@ray-js/types';
1
+ import type { RouteOptions, Router as TRouter } from '@ray-js/types';
2
2
  import { RouterScheduler } from './RouterScheduler';
3
3
  export declare class Router implements TRouter {
4
4
  private urlPrefix;
@@ -19,7 +19,25 @@ export declare class Router implements TRouter {
19
19
  * 标准化路由路径,将 web 标准的地址栏转化到 小程序地址
20
20
  */
21
21
  private normalizeRoute;
22
+ /**
23
+ * 跳转到指定路由
24
+ * @param to - routes.config.ts 中配置的路由地址
25
+ * @param options
26
+ * @param options.subpackage - 分包名
27
+ *
28
+ * @example
29
+ * router.push('/cat', { subpackage: 'packageA' });
30
+ */
22
31
  push(to: string, options?: RouteOptions): void;
32
+ /**
33
+ * 替换当前页到指定路由
34
+ * @param to - routes.config.ts 中配置的路由地址
35
+ * @param options
36
+ * @param options.subpackage - 分包名
37
+ *
38
+ * @example
39
+ * router.replace('/cat', { subpackage: 'packageA' });
40
+ */
23
41
  replace(to: string, options?: RouteOptions): void;
24
42
  reload(): void;
25
43
  go(delta: number): void;
package/lib/Router.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import { navigateBack, navigateTo, reLaunch, redirectTo, switchTab } from '@ray-js/api';
2
3
  import { url } from '@ray-js/library';
3
- import { navigateBack, navigateTo, reLaunch, switchTab, redirectTo } from '@ray-js/api';
4
4
  import { RouterScheduler, currentPage } from './RouterScheduler';
5
5
  function pathRelative(fromPath, toPath) {
6
6
  const from = fromPath.split('/');
@@ -119,6 +119,16 @@ export class Router {
119
119
  }
120
120
  return Promise.resolve(matchedPage);
121
121
  }
122
+
123
+ /**
124
+ * 跳转到指定路由
125
+ * @param to - routes.config.ts 中配置的路由地址
126
+ * @param options
127
+ * @param options.subpackage - 分包名
128
+ *
129
+ * @example
130
+ * router.push('/cat', { subpackage: 'packageA' });
131
+ */
122
132
  push(to, options) {
123
133
  const subpackage = options === null || options === void 0 ? void 0 : options.subpackage;
124
134
  this.normalizeRoute({
@@ -137,6 +147,16 @@ export class Router {
137
147
  }
138
148
  });
139
149
  }
150
+
151
+ /**
152
+ * 替换当前页到指定路由
153
+ * @param to - routes.config.ts 中配置的路由地址
154
+ * @param options
155
+ * @param options.subpackage - 分包名
156
+ *
157
+ * @example
158
+ * router.replace('/cat', { subpackage: 'packageA' });
159
+ */
140
160
  replace(to, options) {
141
161
  const subpackage = options === null || options === void 0 ? void 0 : options.subpackage;
142
162
  this.normalizeRoute({
@@ -168,6 +188,7 @@ export class Router {
168
188
  delta: 1
169
189
  });
170
190
  }
191
+
171
192
  // 获取宿主环境上的 href ,小程序端需要通过 path 进行转换
172
193
  get href() {
173
194
  const page = currentPage();
@@ -1,4 +1,4 @@
1
- import { RouterScheduler as IRouterScheduler, Routes, SubPackages, TabBar } from '@ray-js/types';
1
+ import { RouterScheduler as IRouterScheduler, type Routes, type SubPackages, type TabBar } from '@ray-js/types';
2
2
  export type Route = Routes[number] & {
3
3
  isTabBar: boolean;
4
4
  };
@@ -30,7 +30,7 @@ export declare class RouterScheduler extends IRouterScheduler<Route> {
30
30
  tabBar: TabBar;
31
31
  subpackages?: SubPackages;
32
32
  }): void;
33
- getMatchedPage(pathname: string): import("@ray-js/types").Route & {
33
+ getMatchedPage(pathname: string): import("@ray-js/types").RootRouteItem & {
34
34
  isTabBar: boolean;
35
35
  } & {
36
36
  params: object;
@@ -3,11 +3,11 @@ import "core-js/modules/esnext.iterator.constructor.js";
3
3
  import "core-js/modules/esnext.iterator.find.js";
4
4
  import "core-js/modules/esnext.iterator.for-each.js";
5
5
  import "core-js/modules/esnext.iterator.some.js";
6
- import { compile, match, pathToRegexp } from 'path-to-regexp';
6
+ import { getLaunchOptionsSync } from '@ray-js/api';
7
7
  import { url } from '@ray-js/library';
8
- import slash from 'slash';
9
8
  import { RouterScheduler as IRouterScheduler } from '@ray-js/types';
10
- import { getLaunchOptionsSync } from '@ray-js/api';
9
+ import { compile, match, pathToRegexp } from 'path-to-regexp';
10
+ import slash from 'slash';
11
11
  export function currentPage() {
12
12
  const pages = getCurrentPages();
13
13
  if (pages.length > 0) {
@@ -43,8 +43,7 @@ export class RouterScheduler extends IRouterScheduler {
43
43
  if (!normalizedRoute.startsWith('/')) {
44
44
  normalizedRoute = '/' + normalizedRoute;
45
45
  }
46
- const matchedRoute = this.getRouteByPath(normalizedRoute);
47
- return matchedRoute;
46
+ return this.getRouteByPath(normalizedRoute);
48
47
  }
49
48
 
50
49
  /**
@@ -92,7 +91,8 @@ export class RouterScheduler extends IRouterScheduler {
92
91
  const tabBarList = (tabBar === null || tabBar === void 0 ? void 0 : tabBar.list) || [];
93
92
  subpackages.forEach(subPackage => {
94
93
  const root = subPackage.root;
95
- subPackage.pages.forEach(page => {
94
+ const subPackagesPages = subPackage.routes || subPackage.pages || [];
95
+ subPackagesPages.forEach(page => {
96
96
  this.addSubPackagePage({
97
97
  root,
98
98
  route: page.route || page.path,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/router-mp",
3
- "version": "1.6.31",
3
+ "version": "1.7.0",
4
4
  "description": "Ray Core",
5
5
  "keywords": [
6
6
  "ray"
@@ -23,22 +23,23 @@
23
23
  "watch": "tsc -p ./tsconfig.build.json --module esnext --outDir lib --watch"
24
24
  },
25
25
  "peerDependencies": {
26
- "@ray-js/api": "1.5.17"
26
+ "@ray-js/api": "1.6.32"
27
27
  },
28
28
  "dependencies": {
29
- "@ray-js/env": "1.6.31",
30
- "@ray-js/library": "1.6.31",
31
- "@ray-js/types": "1.6.31",
29
+ "@ray-js/env": "1.7.0",
30
+ "@ray-js/library": "1.7.0",
31
+ "@ray-js/types": "1.7.0",
32
32
  "@react-navigation/core": "^6.4.17",
33
33
  "path-to-regexp": "^6.3.0",
34
34
  "slash": "^5.1.0"
35
35
  },
36
36
  "devDependencies": {
37
- "@ray-js/cli": "1.6.31"
37
+ "@ray-js/cli": "1.7.0",
38
+ "typescript": "^5.8.3"
38
39
  },
39
40
  "publishConfig": {
40
41
  "access": "public",
41
42
  "registry": "https://registry.npmjs.com"
42
43
  },
43
- "gitHead": "4ffefb3e007defc7433b6fccb0a380a153e8120e"
44
+ "gitHead": "c230e01c313aca9700e12d14b80488aae9bec3d3"
44
45
  }