react-router-navigation-confirm
Version:
A collection of components to display a custom confirmation dialog on navigation. More flexible solution to prevent than default react-router 'Prompt'
45 lines • 1.94 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import * as React from 'react';
import { withRouter } from 'react-router-dom';
import { HistoryService } from '../services';
import { noop } from '../utils';
var HistoryListenerContext = React.createContext(undefined);
var HistoryListener = /** @class */ (function (_super) {
__extends(HistoryListener, _super);
function HistoryListener() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.historyService = new HistoryService();
_this.unlisten = noop;
_this.listen = function (_a) {
var key = _a.key;
_this.historyService.add(key);
};
return _this;
}
HistoryListener.prototype.componentDidMount = function () {
this.unlisten = this.props.history.listen(this.listen);
};
HistoryListener.prototype.componentWillUnmount = function () {
this.unlisten();
};
HistoryListener.prototype.render = function () {
var children = this.props.children;
return (React.createElement(HistoryListenerContext.Provider, { value: this.historyService }, children || null));
};
return HistoryListener;
}(React.Component));
var HistoryListenerWithRouter = withRouter(HistoryListener);
export { HistoryListener, HistoryListenerWithRouter, HistoryListenerContext, };
//# sourceMappingURL=HistoryListener.js.map