@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 +21 -0
- package/dist/history/abstract.d.ts +2 -2
- package/dist/history/abstract.mjs +2 -2
- package/dist/history/base.d.ts +1 -1
- package/dist/history/html.d.ts +10 -2
- package/dist/history/html.mjs +5 -3
- package/dist/history/index.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/router.d.ts +1 -1
- package/dist/router.mjs +1 -1
- package/dist/types/index.d.ts +694 -0
- package/dist/types/index.mjs +6 -0
- package/dist/utils/guards.d.ts +1 -1
- package/dist/utils/path.d.ts +1 -1
- package/dist/utils/path.mjs +59 -42
- package/dist/utils/path.spec.mjs +1 -4
- package/package.json +4 -3
- package/src/history/abstract.ts +3 -3
- package/src/history/html.ts +12 -15
- package/src/types/index.ts +858 -0
- package/src/utils/path.spec.ts +1 -13
- package/src/utils/path.ts +62 -42
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):
|
|
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
|
-
|
|
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
|
|
37
|
+
const base = this.router.base;
|
|
38
|
+
const { flag, route } = isPathWithProtocolOrDomain(location, base);
|
|
39
39
|
if (!flag) {
|
|
40
40
|
return false;
|
|
41
41
|
}
|
package/dist/history/base.d.ts
CHANGED
package/dist/history/html.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import {
|
|
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():
|
|
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;
|
package/dist/history/html.mjs
CHANGED
|
@@ -94,7 +94,8 @@ export class HtmlHistory extends BaseRouterHistory {
|
|
|
94
94
|
}
|
|
95
95
|
// 处理外站跳转逻辑
|
|
96
96
|
handleOutside(location, replace = false, isTriggerWithWindow = false) {
|
|
97
|
-
const
|
|
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
|
-
|
|
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) {
|
package/dist/history/index.mjs
CHANGED
package/dist/index.mjs
CHANGED
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():
|
|
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;
|