@tarojs/router 4.0.0-canary.9 → 4.0.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.
@@ -5,6 +5,7 @@ import { bindPageScroll } from '../events/scroll.js';
5
5
  import { setHistory, history } from '../history.js';
6
6
  import { loadAnimateStyle, loadRouterStyle } from '../style.js';
7
7
  import { routesAlias } from '../utils/index.js';
8
+ import NavigationBarHandler from './navigation-bar.js';
8
9
  import stacks from './stack.js';
9
10
 
10
11
  /* eslint-disable dot-notation */
@@ -14,7 +15,9 @@ class PageHandler {
14
15
  this.defaultAnimation = { duration: 300, delay: 50 };
15
16
  this.config = config;
16
17
  this.homePage = getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
18
+ this.originHomePage = this.config.entryPagePath || this.routes[0].path || this.basename;
17
19
  this.mount();
20
+ this.navigationBarHandler = new NavigationBarHandler(this);
18
21
  }
19
22
  get currentPage() {
20
23
  const routePath = getCurrentPage(this.routerMode, this.basename);
@@ -46,14 +49,14 @@ class PageHandler {
46
49
  }
47
50
  set pathname(p) { this.router.pathname = p; }
48
51
  get pathname() { return this.router.pathname; }
52
+ // Note: 把 pathname 转换为原始路径,主要是处理 customRoutes 和 basename
53
+ get originPathname() { return routesAlias.getOrigin(addLeadingSlash(stripBasename(this.pathname, this.basename))); }
49
54
  get basename() { return this.router.basename || ''; }
50
55
  get pageConfig() {
51
- const routePath = addLeadingSlash(stripBasename(this.pathname, this.basename));
52
56
  const homePage = addLeadingSlash(this.homePage);
53
57
  return this.routes.find(r => {
54
- var _a;
55
58
  const pagePath = addLeadingSlash(r.path);
56
- return [pagePath, homePage].includes(routePath) || ((_a = routesAlias.getConfig(pagePath)) === null || _a === void 0 ? void 0 : _a.includes(routePath));
59
+ return [pagePath, homePage].includes(this.originPathname);
57
60
  });
58
61
  }
59
62
  isTabBar(pathname) {
@@ -120,7 +123,7 @@ class PageHandler {
120
123
  this.pathname = history.location.pathname;
121
124
  // Note: 注入页面样式
122
125
  this.animation && loadAnimateStyle(this.animationDuration);
123
- loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
126
+ loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll, this.router.enhanceAnimation);
124
127
  }
125
128
  onReady(page, onLoad = true) {
126
129
  var _a;
@@ -158,6 +161,7 @@ class PageHandler {
158
161
  this.isDefaultNavigationStyle() && pageEl.classList.add('taro_navigation_page');
159
162
  this.addAnimation(pageEl, pageNo === 0);
160
163
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
164
+ this.navigationBarHandler.load();
161
165
  this.bindPageEvents(page, pageConfig);
162
166
  this.triggerRouterChange();
163
167
  }
@@ -170,6 +174,7 @@ class PageHandler {
170
174
  this.isDefaultNavigationStyle() && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page'));
171
175
  this.addAnimation(pageEl, pageNo === 0);
172
176
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
177
+ this.navigationBarHandler.load();
173
178
  this.onReady(page, true);
174
179
  this.bindPageEvents(page, pageConfig);
175
180
  this.triggerRouterChange();
@@ -224,6 +229,7 @@ class PageHandler {
224
229
  pageEl.classList.remove('taro_page_shade');
225
230
  this.addAnimation(pageEl, pageNo === 0);
226
231
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
232
+ this.navigationBarHandler.load();
227
233
  this.bindPageEvents(page, pageConfig);
228
234
  this.triggerRouterChange();
229
235
  }
@@ -233,30 +239,43 @@ class PageHandler {
233
239
  pageEl = this.getPageContainer(page);
234
240
  this.addAnimation(pageEl, pageNo === 0);
235
241
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
242
+ this.navigationBarHandler.load();
236
243
  this.onReady(page, false);
237
244
  this.bindPageEvents(page, pageConfig);
238
245
  this.triggerRouterChange();
239
246
  });
240
247
  }
241
248
  }
242
- hide(page) {
243
- var _a;
249
+ hide(page, animation = false) {
250
+ var _a, _b, _c, _d, _e, _f, _g, _h;
244
251
  if (!page)
245
252
  return;
246
253
  // NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
247
254
  const pageEl = this.getPageContainer(page);
248
255
  if (pageEl) {
249
- if (this.hideTimer) {
250
- clearTimeout(this.hideTimer);
251
- this.hideTimer = null;
252
- pageEl.classList.add('taro_page_shade');
256
+ if (animation) {
257
+ if (this.hideTimer) {
258
+ clearTimeout(this.hideTimer);
259
+ this.hideTimer = null;
260
+ (_c = (_b = (_a = this.lastHidePage) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.add) === null || _c === void 0 ? void 0 : _c.call(_b, 'taro_page_shade');
261
+ }
262
+ this.lastHidePage = pageEl;
263
+ this.hideTimer = setTimeout(() => {
264
+ this.hideTimer = null;
265
+ pageEl.classList.add('taro_page_shade');
266
+ }, this.animationDuration + this.animationDelay);
267
+ (_d = page.onHide) === null || _d === void 0 ? void 0 : _d.call(page);
253
268
  }
254
- this.lastHidePage = pageEl;
255
- this.hideTimer = setTimeout(() => {
256
- this.hideTimer = null;
269
+ else {
270
+ if (this.hideTimer) {
271
+ clearTimeout(this.hideTimer);
272
+ this.hideTimer = null;
273
+ (_g = (_f = (_e = this.lastHidePage) === null || _e === void 0 ? void 0 : _e.classList) === null || _f === void 0 ? void 0 : _f.add) === null || _g === void 0 ? void 0 : _g.call(_f, 'taro_page_shade');
274
+ }
275
+ (_h = page.onHide) === null || _h === void 0 ? void 0 : _h.call(page);
257
276
  pageEl.classList.add('taro_page_shade');
258
- }, this.animationDuration + this.animationDelay);
259
- (_a = page.onHide) === null || _a === void 0 ? void 0 : _a.call(page);
277
+ this.lastHidePage = pageEl;
278
+ }
260
279
  }
261
280
  else {
262
281
  setTimeout(() => this.hide(page), 0);
@@ -1,5 +1,4 @@
1
- import { AppInstance } from '@tarojs/runtime';
2
- import { History } from "../history.js";
3
- import { SpaRouterConfig } from '../../types/router';
4
- declare function createRouter(history: History, app: AppInstance, config: SpaRouterConfig, framework?: string): () => void;
5
- export { createRouter };
1
+ import type { AppInstance } from '@tarojs/runtime';
2
+ import type { History } from 'history';
3
+ import type { SpaRouterConfig } from '../../types/router';
4
+ export declare function createRouter(history: History, app: AppInstance, config: SpaRouterConfig, framework?: string): () => void;
@@ -1,10 +1,9 @@
1
1
  import { __awaiter } from 'tslib';
2
- import { incrementId, addLeadingSlash, eventCenter, stripBasename, Current, createPageConfig, hooks, stringify } from '@tarojs/runtime';
2
+ import { incrementId, addLeadingSlash, eventCenter, stripBasename, Current, safeExecute, createPageConfig, hooks, stringify } from '@tarojs/runtime';
3
3
  import { Action } from 'history';
4
4
  import UniversalRouter from 'universal-router';
5
5
  import { prependBasename } from '../history.js';
6
6
  import { routesAlias } from '../utils/index.js';
7
- import { setTitle } from '../utils/navigate.js';
8
7
  import { RouterConfig } from './index.js';
9
8
  import PageHandler from './page.js';
10
9
  import stacks from './stack.js';
@@ -18,6 +17,10 @@ function createRouter(history, app, config, framework) {
18
17
  }
19
18
  RouterConfig.config = config;
20
19
  const handler = new PageHandler(config, history);
20
+ // Note: 弱网情况下,快速切换 tab,会造成同个页面实例被多次挂在到页面上,原因是资源请求是异步的,短时间内发起多个请求,
21
+ // 会在资源加载完成后,同时走到挂载的逻辑,造成 pageStampId 更新不及时,两个 page 的Id 相同,后面很多操作是通过 getElementById 来进行的
22
+ // 所以需要加一个锁来应对这个情况
23
+ const pageLock = {};
21
24
  routesAlias.set(handler.router.customRoutes);
22
25
  const basename = handler.router.basename;
23
26
  const routes = handler.routes.map(route => {
@@ -39,29 +42,35 @@ function createRouter(history, app, config, framework) {
39
42
  eventCenter.trigger('__taroRouterLaunch', launchParam);
40
43
  (_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
41
44
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
42
- const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
43
- var _c, _d, _e, _f, _g, _h, _j, _k, _l;
44
- handler.pathname = decodeURI(location.pathname);
45
- if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
45
+ const render = (_c) => __awaiter(this, [_c], void 0, function* ({ location, action }) {
46
+ var _d, _e, _f, _g, _h, _j, _k, _l;
47
+ // Note: 由于下面有异步加载操作 先不要在这里去设置 handler.pathname
48
+ const currentPathname = decodeURI(location.pathname);
49
+ if ((_d = window.__taroAppConfig) === null || _d === void 0 ? void 0 : _d.usingWindowScroll)
46
50
  window.scrollTo(0, 0);
47
51
  eventCenter.trigger('__taroRouterChange', {
48
52
  toLocation: {
49
- path: handler.pathname
53
+ path: currentPathname
50
54
  }
51
55
  });
52
- let element, params;
56
+ let element, context, params;
57
+ const routerPath = handler.router.forcePath || currentPathname;
58
+ pageLock[routerPath] = typeof pageLock[routerPath] === 'number' ? pageLock[routerPath] + 1 : 1;
59
+ const currentLock = pageLock[routerPath];
60
+ let postLock;
53
61
  try {
54
- const result = yield router.resolve(handler.router.forcePath || handler.pathname);
55
- [element, , params] = yield Promise.all(result);
62
+ const result = yield router.resolve(routerPath);
63
+ [element, context, params] = yield Promise.all(result);
64
+ postLock = pageLock[routerPath];
56
65
  }
57
66
  catch (error) {
58
67
  if (error.status === 404) {
59
68
  const notFoundEvent = {
60
69
  isEntryPage: stacks.length === 0,
61
- path: handler.pathname,
70
+ path: currentPathname,
62
71
  query: handler.getQuery(createStampId()),
63
72
  };
64
- (_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
73
+ (_e = app.onPageNotFound) === null || _e === void 0 ? void 0 : _e.call(app, notFoundEvent);
65
74
  eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
66
75
  }
67
76
  else if (/Loading hot update .* failed./.test(error.message)) {
@@ -72,15 +81,17 @@ function createRouter(history, app, config, framework) {
72
81
  throw error;
73
82
  }
74
83
  }
75
- if (!element)
84
+ if (!element || currentLock !== postLock)
76
85
  return;
77
- const pageConfig = handler.pageConfig;
78
- let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
79
- let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
80
- let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
81
- let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
86
+ // Note: 异步结束后,在设置 handler.pathname
87
+ // context.pathname universal-router 被处理过了,是发起资源请求的时候传入的 pathname,即 await router.resolve(routerPath) 这个 routerPath
88
+ handler.pathname = context.pathname;
89
+ const { pathname, pageConfig } = handler;
90
+ let enablePullDownRefresh = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.enablePullDownRefresh) || false;
91
+ let navigationStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationStyle) || 'default';
92
+ let navigationBarTextStyle = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarTextStyle) || 'white';
93
+ let navigationBarBackgroundColor = ((_j = config === null || config === void 0 ? void 0 : config.window) === null || _j === void 0 ? void 0 : _j.navigationBarBackgroundColor) || '#000000';
82
94
  if (pageConfig) {
83
- setTitle((_j = pageConfig.navigationBarTitleText) !== null && _j !== void 0 ? _j : document.title);
84
95
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
85
96
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
86
97
  }
@@ -96,7 +107,6 @@ function createRouter(history, app, config, framework) {
96
107
  }
97
108
  eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
98
109
  const currentPage = Current.page;
99
- const pathname = handler.pathname;
100
110
  const methodName = (_k = stacks.method) !== null && _k !== void 0 ? _k : '';
101
111
  const cacheTabs = stacks.getTabs();
102
112
  let shouldLoad = false;
@@ -112,10 +122,11 @@ function createRouter(history, app, config, framework) {
112
122
  }
113
123
  shouldLoad = true;
114
124
  }
115
- else if (currentPage && handler.isTabBar(handler.pathname)) {
125
+ else if (currentPage && handler.isTabBar(pathname)) {
116
126
  if (handler.isSamePage(currentPage))
117
127
  return;
118
128
  if (handler.isTabBar(currentPage.path)) {
129
+ // NOTE: 从 tabBar 页面切换到 tabBar 页面
119
130
  handler.hide(currentPage);
120
131
  stacks.pushTab(currentPage.path.split('?')[0]);
121
132
  }
@@ -129,8 +140,8 @@ function createRouter(history, app, config, framework) {
129
140
  handler.unload(currentPage, stacks.length, true);
130
141
  }
131
142
  }
132
- if (cacheTabs[handler.pathname]) {
133
- stacks.popTab(handler.pathname);
143
+ if (cacheTabs[pathname]) {
144
+ stacks.popTab(pathname);
134
145
  return handler.show(stacks.getItem(0), pageConfig, 0);
135
146
  }
136
147
  shouldLoad = true;
@@ -159,7 +170,7 @@ function createRouter(history, app, config, framework) {
159
170
  shouldLoad = true;
160
171
  }
161
172
  else if (action === 'PUSH') {
162
- handler.hide(currentPage);
173
+ handler.hide(currentPage, true);
163
174
  shouldLoad = true;
164
175
  }
165
176
  if (shouldLoad || stacks.length < 1) {
@@ -188,6 +199,26 @@ function createRouter(history, app, config, framework) {
188
199
  }
189
200
  render({ location: history.location, action: Action.Push });
190
201
  (_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
202
+ window.addEventListener('visibilitychange', () => {
203
+ var _a, _b, _c, _d, _e, _f, _g;
204
+ const currentPath = ((_a = Current.page) === null || _a === void 0 ? void 0 : _a.path) || '';
205
+ const path = currentPath.substring(0, currentPath.indexOf('?'));
206
+ const param = {};
207
+ // app的 onShow/onHide 生命周期的路径信息为当前页面的路径
208
+ Object.assign(param, launchParam, { path });
209
+ if (document.visibilityState === 'visible') {
210
+ (_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, param);
211
+ // 单页面app显示后一刻会触发当前 page.onShow 生命周期函数
212
+ (_d = (_c = Current.page) === null || _c === void 0 ? void 0 : _c.onShow) === null || _d === void 0 ? void 0 : _d.call(_c);
213
+ }
214
+ else {
215
+ // 单页面app隐藏前一刻会触发当前 page.onHide 生命周期函数
216
+ if ((_e = Current.page) === null || _e === void 0 ? void 0 : _e.path) {
217
+ safeExecute((_f = Current.page) === null || _f === void 0 ? void 0 : _f.path, 'onHide');
218
+ }
219
+ (_g = app.onHide) === null || _g === void 0 ? void 0 : _g.call(app, param);
220
+ }
221
+ });
191
222
  return history.listen(render);
192
223
  }
193
224
 
@@ -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,10 +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;
9
- declare function addStyle(css: any): void;
10
- export { loadAnimateStyle, loadRouterStyle, addStyle };
8
+ export declare function loadRouterStyle(enableTabBar: boolean, enableWindowScroll: boolean, enhanceAnimation?: boolean): void;
9
+ /**
10
+ * 插入导航栏相关的样式
11
+ */
12
+ export declare function loadNavigationBarStyle(): void;
13
+ export declare function addStyle(css: any): void;
package/dist/style.js CHANGED
@@ -3,6 +3,10 @@
3
3
  */
4
4
  function loadAnimateStyle(ms = 300) {
5
5
  const css = `
6
+ body {
7
+ /* 防止 iOS 页面滚动 */
8
+ overflow: hidden;
9
+ }
6
10
  .taro_router > .taro_page {
7
11
  position: absolute;
8
12
  left: 0;
@@ -18,6 +22,7 @@ function loadAnimateStyle(ms = 300) {
18
22
  .taro_router > .taro_page.taro_tabbar_page,
19
23
  .taro_router > .taro_page.taro_page_show.taro_page_stationed {
20
24
  transform: none;
25
+ transition: none;
21
26
  }
22
27
 
23
28
  .taro_router > .taro_page.taro_page_show {
@@ -29,7 +34,7 @@ function loadAnimateStyle(ms = 300) {
29
34
  /**
30
35
  * 插入路由相关样式
31
36
  */
32
- function loadRouterStyle(enableTabBar, enableWindowScroll) {
37
+ function loadRouterStyle(enableTabBar, enableWindowScroll, enhanceAnimation) {
33
38
  const css = `
34
39
  .taro_router {
35
40
  position: relative;
@@ -57,9 +62,104 @@ ${enableTabBar ? `
57
62
  }
58
63
 
59
64
  ` : ''}
60
- .taro_page_shade,
65
+ ${enhanceAnimation
66
+ ? `.taro_page_shade:has(+.taro_page_stationed),
67
+ .taro_page_shade.taro_tabbar_page,
68
+ .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) {
69
+ display: none;
70
+ }` : ` .taro_page_shade,
61
71
  .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
62
72
  display: none;
73
+ }`}
74
+ `;
75
+ addStyle(css);
76
+ }
77
+ /**
78
+ * 插入导航栏相关的样式
79
+ */
80
+ function loadNavigationBarStyle() {
81
+ const css = `
82
+ .taro-navigation-bar-show {
83
+ display: flex;
84
+ background: white;
85
+ position: sticky;
86
+ z-index: 500;
87
+ top: 0;
88
+ padding-bottom: 8px;
89
+ padding-top: calc(env(safe-area-inset-top) + 8px);
90
+ justify-content: center;
91
+ align-items: center;
92
+ }
93
+
94
+ .taro-navigation-bar-hide {
95
+ display: none;
96
+ }
97
+
98
+ .taro-navigation-bar-title-wrap {
99
+ display: flex;
100
+ height: 24px;
101
+ }
102
+
103
+ .taro-navigation-bar-title-wrap > .taro-navigation-bar-loading {
104
+ display: none;
105
+ animation: loading 2s linear infinite;
106
+ }
107
+
108
+ .taro-navigation-bar-title-wrap .taro-navigation-bar-loading.taro-navigation-bar-loading-show {
109
+ display: flex;
110
+ }
111
+
112
+ .taro-navigation-bar-title-wrap > .taro-navigation-bar-title {
113
+ font-size: 24px;
114
+ height: 24px;
115
+ line-height: 24px;
116
+ max-width: 100px;
117
+ white-space: nowrap;
118
+ overflow: hidden;
119
+ line-height: 24px;
120
+ text-overflow: ellipsis;
121
+ }
122
+
123
+ @keyframes loading {
124
+ from {
125
+ transform: rotate(0deg);
126
+ }
127
+ to {
128
+ transform: rotate(360deg);
129
+ }
130
+ }
131
+
132
+ @keyframes loading {
133
+ from {
134
+ transform: rotate(0deg);
135
+ }
136
+ to {
137
+ transform: rotate(360deg);
138
+ }
139
+ }
140
+
141
+ .taro-navigation-bar-no-icon > .taro-navigation-bar-home {
142
+ display: none;
143
+ }
144
+
145
+ .taro-navigation-bar-no-icon > .taro-navigation-bar-back {
146
+ display: none;
147
+ }
148
+
149
+ .taro-navigation-bar-home-icon > .taro-navigation-bar-home {
150
+ display: flex;
151
+ left: 8px;
152
+ position: absolute;
153
+ width: 24px;
154
+ height: 24px;
155
+ }
156
+
157
+ .taro-navigation-bar-back-icon > .taro-navigation-bar-back {
158
+ display: flex;
159
+ left: 8px;
160
+ position: absolute;
161
+ width: 24px;
162
+ height: 24px;
63
163
  }
64
164
  `;
65
165
  addStyle(css);
@@ -72,4 +172,4 @@ function addStyle(css) {
72
172
  document.getElementsByTagName('head')[0].appendChild(style);
73
173
  }
74
174
 
75
- export { addStyle, loadAnimateStyle, loadRouterStyle };
175
+ export { addStyle, loadAnimateStyle, loadNavigationBarStyle, loadRouterStyle };
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,5 +1,4 @@
1
1
  import { addLeadingSlash } from '@tarojs/runtime';
2
- import 'tslib';
3
2
 
4
3
  class RoutesAlias {
5
4
  constructor() {
@@ -1,4 +1,9 @@
1
- declare const isWeixin: () => boolean;
2
- declare const isDingTalk: () => boolean;
3
- declare function setTitle(title: string): Promise<string>;
4
- export { isWeixin, isDingTalk, setTitle };
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
+ backgroundColor: string;
7
+ frontColor: string;
8
+ }): void;
9
+ export declare function setNavigationBarLoading(loading: boolean): void;
@@ -1,25 +1,31 @@
1
- import { __awaiter } from 'tslib';
1
+ import { eventCenter } from '@tarojs/runtime';
2
2
 
3
- let preTitle = document.title;
4
- let isLoadDdEntry = false;
5
3
  const isWeixin = () => !!navigator.userAgent.match(/\bMicroMessenger\b/ig);
6
4
  const isDingTalk = () => !!navigator.userAgent.match(/\bDingTalk\b/ig);
7
- function setTitle(title) {
8
- return __awaiter(this, void 0, void 0, function* () {
9
- if (preTitle === title)
10
- return title;
11
- document.title = title;
12
- preTitle = title;
13
- if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
14
- if (!isLoadDdEntry) {
15
- isLoadDdEntry = true;
16
- require('dingtalk-jsapi/platform');
17
- }
18
- const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
19
- setDingTitle({ title });
5
+ let preTitle = document.title;
6
+ let isLoadDdEntry = false;
7
+ function setMpaTitle(title) {
8
+ if (preTitle === title)
9
+ return;
10
+ document.title = title;
11
+ preTitle = title;
12
+ if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
13
+ if (!isLoadDdEntry) {
14
+ isLoadDdEntry = true;
15
+ require('dingtalk-jsapi/platform');
20
16
  }
21
- return title;
22
- });
17
+ const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
18
+ setDingTitle({ title });
19
+ }
20
+ }
21
+ function setTitle(title) {
22
+ eventCenter.trigger('__taroH5SetNavigationBarTitle', title);
23
+ }
24
+ function setNavigationBarStyle(option) {
25
+ eventCenter.trigger('__taroH5setNavigationBarColor', option);
26
+ }
27
+ function setNavigationBarLoading(loading) {
28
+ eventCenter.trigger('__taroH5setNavigationBarLoading', loading);
23
29
  }
24
30
 
25
- export { isDingTalk, isWeixin, setTitle };
31
+ export { isDingTalk, isWeixin, setMpaTitle, setNavigationBarLoading, setNavigationBarStyle, setTitle };
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "@tarojs/router",
3
- "version": "4.0.0-canary.9",
3
+ "version": "4.0.0",
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,45 +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-canary.9",
48
- "@tarojs/taro": "4.0.0-canary.9"
37
+ "@tarojs/components": "4.0.0",
38
+ "@tarojs/taro": "4.0.0",
39
+ "@tarojs/shared": "4.0.0",
40
+ "@tarojs/runtime": "4.0.0"
49
41
  },
50
42
  "peerDependencies": {
51
- "@tarojs/runtime": "4.0.0-canary.9",
52
- "@tarojs/taro": "4.0.0-canary.9"
43
+ "@tarojs/runtime": "4.0.0",
44
+ "@tarojs/taro": "4.0.0",
45
+ "@tarojs/shared": "4.0.0"
53
46
  },
54
47
  "scripts": {
48
+ "prod": "pnpm run build",
55
49
  "prebuild": "pnpm run clean",
56
50
  "build": "pnpm run rollup --environment NODE_ENV:production",
57
51
  "clean": "rimraf --impl=move-remove ./dist",
58
52
  "dev": "pnpm run rollup --environment NODE_ENV:development -w",
59
- "rollup": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --bundleConfigAsCjs",
60
- "test": "cross-env NODE_ENV=jest jest",
61
- "test:ci": "cross-env NODE_ENV=jest jest --ci -i --coverage --silent",
62
- "test:dev": "cross-env NODE_ENV=jest jest --watch"
53
+ "rollup": "rollup --config rollup.config.mts --configPlugin typescript"
63
54
  }
64
55
  }
package/types/api.d.ts CHANGED
@@ -11,3 +11,8 @@ export interface Option extends Base {
11
11
  export interface NavigateBackOption extends Base {
12
12
  delta: number
13
13
  }
14
+
15
+ export interface NavigateOption extends BaseOption {
16
+ url: string
17
+ events?: Record<string, any>
18
+ }
package/types/router.d.ts CHANGED
@@ -12,6 +12,8 @@ export interface Router {
12
12
  customRoutes?: Record<string, string | string[]>
13
13
  pathname: string
14
14
  forcePath?: string
15
+ /** 加上这个参数,可以解决返回页面的时候白屏的问题,但是某些不支持 :has() 选择器的浏览器会有问题 */
16
+ enhanceAnimation?: boolean
15
17
  }
16
18
 
17
19
  export interface SpaRouterConfig extends AppConfig {