@esmx/router 3.0.0-rc.12 → 3.0.0-rc.14

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Vanelink
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -9,7 +9,7 @@ export declare class AbstractHistory extends BaseRouterHistory {
9
9
  }): Promise<void>;
10
10
  destroy(): void;
11
11
  setupListeners(): void;
12
- isSameHost(location: RouterRawLocation, route: Route): any;
12
+ isSameHost(location: RouterRawLocation, route: Route): boolean;
13
13
  handleOutside(location: RouterRawLocation, replace?: boolean, isTriggerWithWindow?: boolean): boolean;
14
14
  push(location: RouterRawLocation): Promise<void>;
15
15
  /**
@@ -22,7 +22,7 @@ export declare class AbstractHistory extends BaseRouterHistory {
22
22
  */
23
23
  replaceWindow(location: RouterRawLocation): Promise<void>;
24
24
  jump(location: RouterRawLocation, replace?: boolean): Promise<void>;
25
- private _jump;
25
+ _jump(location: RouterRawLocation, replace?: boolean, isTriggerWithWindow?: boolean): Promise<void>;
26
26
  go(delta: number): void;
27
27
  forward(): void;
28
28
  back(): void;
@@ -7,7 +7,6 @@ export class AbstractHistory extends BaseRouterHistory {
7
7
  super(router);
8
8
  this.index = -1;
9
9
  this.stack = [];
10
- this.init();
11
10
  }
12
11
  async init({ replace } = { replace: true }) {
13
12
  const { initUrl } = this.router.options;
@@ -35,7 +34,8 @@ export class AbstractHistory extends BaseRouterHistory {
35
34
  }
36
35
  // 处理外站跳转逻辑
37
36
  handleOutside(location, replace = false, isTriggerWithWindow = false) {
38
- const { flag, route } = isPathWithProtocolOrDomain(location);
37
+ const base = this.router.base;
38
+ const { flag, route } = isPathWithProtocolOrDomain(location, base);
39
39
  if (!flag) {
40
40
  return false;
41
41
  }
@@ -8,7 +8,7 @@ export declare abstract class BaseRouterHistory implements RouterHistory {
8
8
  /**
9
9
  * 路由是否冻结
10
10
  */
11
- get isFrozen(): any;
11
+ get isFrozen(): boolean;
12
12
  /**
13
13
  * 匹配的当前路由
14
14
  */
@@ -1,8 +1,16 @@
1
- import { type RouterInstance, type RouterRawLocation } from '../types';
1
+ import type { RouterInstance, RouterRawLocation } from '../types';
2
2
  import { BaseRouterHistory } from './base';
3
3
  export declare class HtmlHistory extends BaseRouterHistory {
4
4
  constructor(router: RouterInstance);
5
- getCurrentLocation(): any;
5
+ getCurrentLocation(): {
6
+ state: any;
7
+ query?: Record<string, string | undefined>;
8
+ queryArray: Record<string, string[]>;
9
+ params?: Record<string, string>;
10
+ hash?: string;
11
+ path: string;
12
+ base: string;
13
+ };
6
14
  onPopState: (e: PopStateEvent) => void;
7
15
  init({ replace }?: {
8
16
  replace?: boolean;
@@ -94,7 +94,8 @@ export class HtmlHistory extends BaseRouterHistory {
94
94
  }
95
95
  // 处理外站跳转逻辑
96
96
  handleOutside(location, replace = false, isTriggerWithWindow = false) {
97
- const { flag, route } = isPathWithProtocolOrDomain(location);
97
+ const base = this.router.base;
98
+ const { flag, route } = isPathWithProtocolOrDomain(location, base);
98
99
  const router = this.router;
99
100
  const { handleOutside, validateOutside } = router.options;
100
101
  const isSameHost = !flag || window.location.hostname === route.hostname;
@@ -103,13 +104,14 @@ export class HtmlHistory extends BaseRouterHistory {
103
104
  return false;
104
105
  }
105
106
  }
106
- if (handleOutside == null ? void 0 : handleOutside({
107
+ const res = handleOutside == null ? void 0 : handleOutside({
107
108
  router,
108
109
  route,
109
110
  replace,
110
111
  isTriggerWithWindow,
111
112
  isSameHost
112
- })) {
113
+ });
114
+ if (res === false) {
113
115
  return true;
114
116
  }
115
117
  if (replace) {
@@ -1,4 +1,4 @@
1
- import { RouterMode } from "../types";
1
+ import { RouterMode } from "../types/index.mjs";
2
2
  import { AbstractHistory } from "./abstract.mjs";
3
3
  import { HtmlHistory } from "./html.mjs";
4
4
  export function createHistory({
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  export { createRouter } from "./router.mjs";
2
- export * from "./types";
2
+ export * from "./types/index.mjs";
3
3
  export * from "./utils/index.mjs";
package/dist/router.d.ts CHANGED
@@ -106,6 +106,6 @@ export declare class Router implements RouterInstance {
106
106
  go(delta?: number): void;
107
107
  forward(): void;
108
108
  back(): void;
109
- getRoutes(): any;
109
+ getRoutes(): import("./types").RouteMatch[];
110
110
  }
111
111
  export declare function createRouter(options: RouterOptions): RouterInstance;
package/dist/router.mjs CHANGED
@@ -4,7 +4,7 @@ import { createRouterMatcher } from "./matcher/index.mjs";
4
4
  import {
5
5
  RouterMode,
6
6
  StateLayerConfigKey
7
- } from "./types";
7
+ } from "./types/index.mjs";
8
8
  import { inBrowser, normalizePath, regexDomain } from "./utils/index.mjs";
9
9
  const baseValue = Number(Date.now());
10
10
  let layerIdOffset = 0;