@tarojs/router 4.0.0-beta.75 → 4.0.0-beta.77

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.
@@ -38,10 +38,10 @@ function createRouter(history, app, config, framework) {
38
38
  eventCenter.trigger('__taroRouterLaunch', launchParam);
39
39
  (_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
40
40
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
41
- const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
42
- var _c, _d, _e, _f, _g, _h, _j, _k;
41
+ const render = (_c) => __awaiter(this, [_c], void 0, function* ({ location, action }) {
42
+ var _d, _e, _f, _g, _h, _j, _k, _l;
43
43
  handler.pathname = decodeURI(location.pathname);
44
- if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
44
+ if ((_d = window.__taroAppConfig) === null || _d === void 0 ? void 0 : _d.usingWindowScroll)
45
45
  window.scrollTo(0, 0);
46
46
  eventCenter.trigger('__taroRouterChange', {
47
47
  toLocation: {
@@ -60,7 +60,7 @@ function createRouter(history, app, config, framework) {
60
60
  path: handler.pathname,
61
61
  query: handler.getQuery(createStampId()),
62
62
  };
63
- (_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
63
+ (_e = app.onPageNotFound) === null || _e === void 0 ? void 0 : _e.call(app, notFoundEvent);
64
64
  eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
65
65
  }
66
66
  else if (/Loading hot update .* failed./.test(error.message)) {
@@ -74,10 +74,10 @@ function createRouter(history, app, config, framework) {
74
74
  if (!element)
75
75
  return;
76
76
  const pageConfig = handler.pageConfig;
77
- let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
78
- let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
79
- let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
80
- let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
77
+ let enablePullDownRefresh = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.enablePullDownRefresh) || false;
78
+ let navigationStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationStyle) || 'default';
79
+ let navigationBarTextStyle = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarTextStyle) || 'white';
80
+ let navigationBarBackgroundColor = ((_j = config === null || config === void 0 ? void 0 : config.window) === null || _j === void 0 ? void 0 : _j.navigationBarBackgroundColor) || '#000000';
81
81
  if (pageConfig) {
82
82
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
83
83
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
@@ -95,7 +95,7 @@ function createRouter(history, app, config, framework) {
95
95
  eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
96
96
  const currentPage = Current.page;
97
97
  const pathname = handler.pathname;
98
- const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
98
+ const methodName = (_k = stacks.method) !== null && _k !== void 0 ? _k : '';
99
99
  const cacheTabs = stacks.getTabs();
100
100
  let shouldLoad = false;
101
101
  stacks.method = '';
@@ -114,6 +114,7 @@ function createRouter(history, app, config, framework) {
114
114
  if (handler.isSamePage(currentPage))
115
115
  return;
116
116
  if (handler.isTabBar(currentPage.path)) {
117
+ // NOTE: 从 tabBar 页面切换到 tabBar 页面
117
118
  handler.hide(currentPage);
118
119
  stacks.pushTab(currentPage.path.split('?')[0]);
119
120
  }
@@ -157,11 +158,11 @@ function createRouter(history, app, config, framework) {
157
158
  shouldLoad = true;
158
159
  }
159
160
  else if (action === 'PUSH') {
160
- handler.hide(currentPage);
161
+ handler.hide(currentPage, true);
161
162
  shouldLoad = true;
162
163
  }
163
164
  if (shouldLoad || stacks.length < 1) {
164
- const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
165
+ const el = (_l = element.default) !== null && _l !== void 0 ? _l : element;
165
166
  const loadConfig = Object.assign({}, pageConfig);
166
167
  const stacksIndex = stacks.length;
167
168
  delete loadConfig['path'];
@@ -1,4 +1,4 @@
1
- import { PageInstance } from '@tarojs/runtime';
1
+ import type { PageInstance } from '@tarojs/runtime';
2
2
  declare class Stacks {
3
3
  stacks: PageInstance[];
4
4
  backDelta: number;
@@ -23,4 +23,4 @@ declare class Stacks {
23
23
  removeTab(path: string): void;
24
24
  }
25
25
  declare const stacks: Stacks;
26
- export { stacks as default };
26
+ export default stacks;
package/dist/style.d.ts CHANGED
@@ -1,14 +1,13 @@
1
1
  /**
2
2
  * 插入页面动画需要的样式
3
3
  */
4
- declare function loadAnimateStyle(ms?: number): void;
4
+ export declare function loadAnimateStyle(ms?: number): void;
5
5
  /**
6
6
  * 插入路由相关样式
7
7
  */
8
- declare function loadRouterStyle(enableTabBar: boolean, enableWindowScroll: boolean): void;
8
+ export declare function loadRouterStyle(enableTabBar: boolean, enableWindowScroll: boolean): void;
9
9
  /**
10
10
  * 插入导航栏相关的样式
11
11
  */
12
- declare function loadNavigationBarStyle(): void;
13
- declare function addStyle(css: any): void;
14
- export { loadAnimateStyle, loadRouterStyle, loadNavigationBarStyle, addStyle };
12
+ export declare function loadNavigationBarStyle(): void;
13
+ export declare function addStyle(css: any): void;
package/dist/style.js CHANGED
@@ -4,7 +4,8 @@
4
4
  function loadAnimateStyle(ms = 300) {
5
5
  const css = `
6
6
  body {
7
- overflow: hidden; // 防止 iOS 页面滚动
7
+ /* 防止 iOS 页面滚动 */
8
+ overflow: hidden;
8
9
  }
9
10
  .taro_router > .taro_page {
10
11
  position: absolute;
@@ -61,8 +62,9 @@ ${enableTabBar ? `
61
62
  }
62
63
 
63
64
  ` : ''}
64
- .taro_page_shade,
65
- .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
65
+ .taro_page_shade:has(+.taro_page_stationed),
66
+ .taro_page_shade.taro_tabbar_page,
67
+ .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child):has(+.taro_page_stationed) {
66
68
  display: none;
67
69
  }
68
70
  `;
@@ -130,7 +132,7 @@ function loadNavigationBarStyle() {
130
132
  to {
131
133
  transform: rotate(360deg);
132
134
  }
133
- }
135
+ }
134
136
 
135
137
  .taro-navigation-bar-no-icon > .taro-navigation-bar-home {
136
138
  display: none;
package/dist/tabbar.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  import { AppConfig } from '@tarojs/taro';
2
- import { History } from "./history.js";
3
- declare function initTabbar(config: AppConfig, history: History): void;
4
- export { initTabbar };
2
+ import type { History } from 'history';
3
+ export declare function initTabbar(config: AppConfig, history: History): void;
@@ -6,6 +6,5 @@ declare class RoutesAlias {
6
6
  getAlias: (url?: string) => string;
7
7
  getAll: (url?: string) => string[];
8
8
  }
9
- declare const routesAlias: RoutesAlias;
10
- export { routesAlias };
11
- export * from "./navigate.js";
9
+ export declare const routesAlias: RoutesAlias;
10
+ export * from './navigate';
@@ -1,10 +1,9 @@
1
- declare const isWeixin: () => boolean;
2
- declare const isDingTalk: () => boolean;
3
- declare function setMpaTitle(title: string): void;
4
- declare function setTitle(title: string): void;
5
- declare function setNavigationBarStyle(option: {
1
+ export declare const isWeixin: () => boolean;
2
+ export declare const isDingTalk: () => boolean;
3
+ export declare function setMpaTitle(title: string): void;
4
+ export declare function setTitle(title: string): void;
5
+ export declare function setNavigationBarStyle(option: {
6
6
  backgroundColor: string;
7
7
  frontColor: string;
8
8
  }): void;
9
- declare function setNavigationBarLoading(loading: boolean): void;
10
- export { isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle, setNavigationBarLoading };
9
+ export declare function setNavigationBarLoading(loading: boolean): void;
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "@tarojs/router",
3
- "version": "4.0.0-beta.75",
3
+ "version": "4.0.0-beta.77",
4
4
  "description": "Taro-router",
5
+ "author": "O2Team",
6
+ "license": "MIT",
5
7
  "browser": "dist/index.js",
6
8
  "main:h5": "dist/index.esm.js",
7
9
  "main": "dist/index.js",
@@ -20,47 +22,34 @@
20
22
  "keywords": [
21
23
  "router"
22
24
  ],
23
- "author": "O2Team",
24
- "license": "MIT",
25
+ "engines": {
26
+ "node": ">= 18"
27
+ },
25
28
  "dependencies": {
26
29
  "dingtalk-jsapi": "~2.15.2",
27
- "history": "^5.1.0",
30
+ "history": "^5.3.0",
28
31
  "mobile-detect": "^1.4.2",
29
- "query-string": "^7.1.1",
32
+ "query-string": "^9.0.0",
30
33
  "tslib": "^2.6.2",
31
- "universal-router": "^8.3.0"
34
+ "universal-router": "^9.2.0"
32
35
  },
33
36
  "devDependencies": {
34
- "@rollup/plugin-commonjs": "^25.0.7",
35
- "@rollup/plugin-node-resolve": "^15.2.3",
36
- "@rollup/plugin-typescript": "^11.1.0",
37
- "@types/jest": "^29.4.0",
38
- "jest": "^29.3.1",
39
- "jest-cli": "^29.3.1",
40
- "jest-environment-jsdom": "^29.6.4",
41
- "jsdom": "^21.1.0",
42
- "rollup": "^3.8.1",
43
- "rollup-plugin-node-externals": "^5.0.0",
44
- "rollup-plugin-ts": "^3.0.2",
45
- "ts-jest": "^29.0.5",
46
- "typescript": "^4.7.4",
47
- "@tarojs/runtime": "4.0.0-beta.75",
48
- "@tarojs/taro": "4.0.0-beta.75",
49
- "@tarojs/shared": "4.0.0-beta.75"
37
+ "@tarojs/components": "4.0.0-beta.77",
38
+ "@tarojs/taro": "4.0.0-beta.77",
39
+ "@tarojs/runtime": "4.0.0-beta.77",
40
+ "@tarojs/shared": "4.0.0-beta.77"
50
41
  },
51
42
  "peerDependencies": {
52
- "@tarojs/runtime": "4.0.0-beta.75",
53
- "@tarojs/taro": "4.0.0-beta.75",
54
- "@tarojs/shared": "4.0.0-beta.75"
43
+ "@tarojs/runtime": "4.0.0-beta.77",
44
+ "@tarojs/taro": "4.0.0-beta.77",
45
+ "@tarojs/shared": "4.0.0-beta.77"
55
46
  },
56
47
  "scripts": {
48
+ "prod": "pnpm run build",
57
49
  "prebuild": "pnpm run clean",
58
50
  "build": "pnpm run rollup --environment NODE_ENV:production",
59
51
  "clean": "rimraf --impl=move-remove ./dist",
60
52
  "dev": "pnpm run rollup --environment NODE_ENV:development -w",
61
- "rollup": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --bundleConfigAsCjs",
62
- "test": "cross-env NODE_ENV=jest jest",
63
- "test:ci": "cross-env NODE_ENV=jest jest --ci -i --coverage --silent",
64
- "test:dev": "cross-env NODE_ENV=jest jest --watch"
53
+ "rollup": "rollup --config rollup.config.mts --configPlugin typescript"
65
54
  }
66
55
  }
@@ -1,66 +0,0 @@
1
- import { Action, createBrowserHistory, createHashHistory, Blocker, BrowserHistoryOptions, HashHistoryOptions, History, Listener, Location, Path, To } from "history";
2
- import { IH5RouterConfig } from "@tarojs/taro/types/compile";
3
- import { StateEvent } from "../types/history";
4
- import { MpaRouterConfig, SpaRouterConfig } from '../types/router';
5
- import Taro from "@tarojs/taro";
6
- import { AppInstance } from "@tarojs/runtime";
7
- import { MpaRouterConfig as MpaRouterConfig$0 } from "../../types/router";
8
- import { SpaRouterConfig as SpaRouterConfig$0 } from "../../types/router";
9
- declare let history: History;
10
- declare class MpaHistory implements History {
11
- action: Action;
12
- get location(): Location;
13
- createHref(_to: To): string;
14
- parseUrl(to: Partial<Path>): string;
15
- push(to: Partial<Path>, _state?: Record<string, unknown>): void;
16
- replace(to: Partial<Path>, _state?: Record<string, unknown>): void;
17
- go(delta: number): void;
18
- back: () => void;
19
- forward: () => void;
20
- listen(listener: Listener): () => void;
21
- block(_blocker: Blocker): () => void;
22
- pushState: globalThis.History["pushState"];
23
- replaceState: globalThis.History["replaceState"];
24
- eventState(action: Required<StateEvent>["action"]): (data: any, unused: string, url?: string | URL | null) => any;
25
- }
26
- declare function setHistory(h: History, base?: string): void;
27
- declare function createMpaHistory(_?: HashHistoryOptions | BrowserHistoryOptions): MpaHistory;
28
- declare function setHistoryMode(mode?: IH5RouterConfig["mode"], base?: string): void;
29
- declare function prependBasename(url?: string): string;
30
- declare function navigateTo(option: Taro.navigateTo.Option): ReturnType<typeof Taro.navigateTo>;
31
- declare function redirectTo(option: Taro.redirectTo.Option): ReturnType<typeof Taro.redirectTo>;
32
- declare function navigateBack(option?: Taro.navigateBack.Option): ReturnType<typeof Taro.navigateBack>;
33
- declare function switchTab(option: Taro.switchTab.Option): ReturnType<typeof Taro.switchTab>;
34
- declare function reLaunch(option: Taro.reLaunch.Option): ReturnType<typeof Taro.reLaunch>;
35
- declare function getCurrentPages(): Taro.Page[];
36
- // TODO 支持多路由 (APP 生命周期仅触发一次)
37
- /** Note: 关于多页面应用
38
- * - 需要配置路由映射(根目录跳转、404 页面……)
39
- * - app.onPageNotFound 事件不支持
40
- * - 应用生命周期可能多次触发
41
- * - TabBar 会多次加载
42
- * - 不支持路由动画
43
- */
44
- declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig$0, framework?: string): Promise<void>;
45
- declare function createRouter(history: History, app: AppInstance, config: SpaRouterConfig$0, framework?: string): () => void;
46
- declare class RoutesAlias {
47
- conf: Array<string[]>;
48
- set(customRoutes?: Record<string, string | string[]>): void;
49
- getConfig: (url?: string) => string[];
50
- getOrigin: (url?: string) => string;
51
- getAlias: (url?: string) => string;
52
- getAll: (url?: string) => string[];
53
- }
54
- declare const routesAlias: RoutesAlias;
55
- declare const isWeixin: () => boolean;
56
- declare const isDingTalk: () => boolean;
57
- declare function setMpaTitle(title: string): void;
58
- declare function setTitle(title: string): void;
59
- declare function setNavigationBarStyle(option: {
60
- backgroundColor: string;
61
- frontColor: string;
62
- }): void;
63
- declare function setNavigationBarLoading(loading: boolean): void;
64
- declare function handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
65
- declare function handleAppMountWithTabbar(config: SpaRouterConfig | MpaRouterConfig, history: History, appId?: string): void;
66
- export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle, setNavigationBarLoading, handleAppMount, handleAppMountWithTabbar };
@@ -1,66 +0,0 @@
1
- import { Action, createBrowserHistory, createHashHistory, Blocker, BrowserHistoryOptions, HashHistoryOptions, History, Listener, Location, Path, To } from "history";
2
- import { IH5RouterConfig } from "@tarojs/taro/types/compile";
3
- import { StateEvent } from "../types/history";
4
- import { MpaRouterConfig, SpaRouterConfig } from '../types/router';
5
- import Taro from "@tarojs/taro";
6
- import { AppInstance } from "@tarojs/runtime";
7
- import { MpaRouterConfig as MpaRouterConfig$0 } from "../../types/router";
8
- import { SpaRouterConfig as SpaRouterConfig$0 } from "../../types/router";
9
- declare let history: History;
10
- declare class MpaHistory implements History {
11
- action: Action;
12
- get location(): Location;
13
- createHref(_to: To): string;
14
- parseUrl(to: Partial<Path>): string;
15
- push(to: Partial<Path>, _state?: Record<string, unknown>): void;
16
- replace(to: Partial<Path>, _state?: Record<string, unknown>): void;
17
- go(delta: number): void;
18
- back: () => void;
19
- forward: () => void;
20
- listen(listener: Listener): () => void;
21
- block(_blocker: Blocker): () => void;
22
- pushState: globalThis.History["pushState"];
23
- replaceState: globalThis.History["replaceState"];
24
- eventState(action: Required<StateEvent>["action"]): (data: any, unused: string, url?: string | URL | null) => any;
25
- }
26
- declare function setHistory(h: History, base?: string): void;
27
- declare function createMpaHistory(_?: HashHistoryOptions | BrowserHistoryOptions): MpaHistory;
28
- declare function setHistoryMode(mode?: IH5RouterConfig["mode"], base?: string): void;
29
- declare function prependBasename(url?: string): string;
30
- declare function navigateTo(option: Taro.navigateTo.Option): ReturnType<typeof Taro.navigateTo>;
31
- declare function redirectTo(option: Taro.redirectTo.Option): ReturnType<typeof Taro.redirectTo>;
32
- declare function navigateBack(option?: Taro.navigateBack.Option): ReturnType<typeof Taro.navigateBack>;
33
- declare function switchTab(option: Taro.switchTab.Option): ReturnType<typeof Taro.switchTab>;
34
- declare function reLaunch(option: Taro.reLaunch.Option): ReturnType<typeof Taro.reLaunch>;
35
- declare function getCurrentPages(): Taro.Page[];
36
- // TODO 支持多路由 (APP 生命周期仅触发一次)
37
- /** Note: 关于多页面应用
38
- * - 需要配置路由映射(根目录跳转、404 页面……)
39
- * - app.onPageNotFound 事件不支持
40
- * - 应用生命周期可能多次触发
41
- * - TabBar 会多次加载
42
- * - 不支持路由动画
43
- */
44
- declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig$0, framework?: string): Promise<void>;
45
- declare function createRouter(history: History, app: AppInstance, config: SpaRouterConfig$0, framework?: string): () => void;
46
- declare class RoutesAlias {
47
- conf: Array<string[]>;
48
- set(customRoutes?: Record<string, string | string[]>): void;
49
- getConfig: (url?: string) => string[];
50
- getOrigin: (url?: string) => string;
51
- getAlias: (url?: string) => string;
52
- getAll: (url?: string) => string[];
53
- }
54
- declare const routesAlias: RoutesAlias;
55
- declare const isWeixin: () => boolean;
56
- declare const isDingTalk: () => boolean;
57
- declare function setMpaTitle(title: string): void;
58
- declare function setTitle(title: string): void;
59
- declare function setNavigationBarStyle(option: {
60
- backgroundColor: string;
61
- frontColor: string;
62
- }): void;
63
- declare function setNavigationBarLoading(loading: boolean): void;
64
- declare function handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
65
- declare function handleAppMountWithTabbar(config: SpaRouterConfig | MpaRouterConfig, history: History, appId?: string): void;
66
- export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle, setNavigationBarLoading, handleAppMount, handleAppMountWithTabbar };