@saber2pr/react-router 0.0.8 → 0.0.9
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/history/index.d.ts +4 -2
- package/lib/history/index.js +7 -4
- package/package.json +1 -1
package/lib/history/index.d.ts
CHANGED
@@ -7,5 +7,7 @@ export declare type History = {
|
|
7
7
|
location: Location;
|
8
8
|
push(url: string): void;
|
9
9
|
};
|
10
|
-
export declare const createLocation: () => Location;
|
11
|
-
export declare const createHashHistory: (
|
10
|
+
export declare const createLocation: (init: boolean) => Location;
|
11
|
+
export declare const createHashHistory: ({ init }?: {
|
12
|
+
init: boolean;
|
13
|
+
}) => History;
|
package/lib/history/index.js
CHANGED
@@ -18,16 +18,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
* @Last Modified time: 2019-10-15 22:59:53
|
19
19
|
*/
|
20
20
|
var utils_1 = require("../utils");
|
21
|
-
exports.createLocation = function () {
|
21
|
+
exports.createLocation = function (init) {
|
22
22
|
if (window.location.hash) {
|
23
23
|
return { pathname: utils_1.getHash() };
|
24
24
|
}
|
25
25
|
else {
|
26
|
-
|
26
|
+
if (init) {
|
27
|
+
window.location.hash = "/";
|
28
|
+
}
|
27
29
|
return { pathname: "/" };
|
28
30
|
}
|
29
31
|
};
|
30
|
-
exports.createHashHistory = function () {
|
32
|
+
exports.createHashHistory = function (_a) {
|
33
|
+
var init = (_a === void 0 ? { init: true } : _a).init;
|
31
34
|
var listeners = [];
|
32
35
|
var listen = function (listener) {
|
33
36
|
listeners.push(listener);
|
@@ -37,7 +40,7 @@ exports.createHashHistory = function () {
|
|
37
40
|
window.location.hash = pathname;
|
38
41
|
listeners.forEach(function (listener) { return listener(__assign(__assign({}, location), { pathname: pathname })); });
|
39
42
|
};
|
40
|
-
var location = exports.createLocation();
|
43
|
+
var location = exports.createLocation(init);
|
41
44
|
window.addEventListener("popstate", function () { return push(utils_1.getHash()); });
|
42
45
|
return {
|
43
46
|
listen: listen,
|