@saber2pr/react-router 0.0.8 → 0.0.10
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/components/nav-link.js +11 -3
- package/lib/history/index.d.ts +4 -2
- package/lib/history/index.js +7 -4
- package/package.json +1 -1
@@ -37,6 +37,17 @@ function joinClassnames() {
|
|
37
37
|
}
|
38
38
|
function NavLink(_a) {
|
39
39
|
var _b = _a.activeClassName, activeClassName = _b === void 0 ? "active" : _b, activeStyle = _a.activeStyle, classNameProp = _a.className, exact = _a.exact, isActiveProp = _a.isActive, styleProp = _a.style, to = _a.to, useBrowserLink = _a.useBrowserLink, rest = __rest(_a, ["activeClassName", "activeStyle", "className", "exact", "isActive", "style", "to", "useBrowserLink"]);
|
40
|
+
if (useBrowserLink) {
|
41
|
+
var pathToMatch = window.location.pathname;
|
42
|
+
var isActive = isActiveProp
|
43
|
+
? isActiveProp(to, pathToMatch)
|
44
|
+
: to === pathToMatch;
|
45
|
+
var className = isActive
|
46
|
+
? joinClassnames(classNameProp, activeClassName)
|
47
|
+
: classNameProp;
|
48
|
+
var style = isActive ? __assign(__assign({}, styleProp), activeStyle) : styleProp;
|
49
|
+
return react_1.default.createElement("a", __assign({ className: className, style: style, href: to }, rest));
|
50
|
+
}
|
40
51
|
return (react_1.default.createElement(context_1.RouterContext.Consumer, null, function (context) {
|
41
52
|
var currentLocation = context.location;
|
42
53
|
var pathToMatch = currentLocation.pathname;
|
@@ -47,9 +58,6 @@ function NavLink(_a) {
|
|
47
58
|
? joinClassnames(classNameProp, activeClassName)
|
48
59
|
: classNameProp;
|
49
60
|
var style = isActive ? __assign(__assign({}, styleProp), activeStyle) : styleProp;
|
50
|
-
if (useBrowserLink) {
|
51
|
-
return react_1.default.createElement("a", __assign({ className: className, style: style, href: to }, rest));
|
52
|
-
}
|
53
61
|
return react_1.default.createElement(link_1.Link, __assign({ className: className, style: style, to: to }, rest));
|
54
62
|
}));
|
55
63
|
}
|
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,
|