UNPKG

@makeen.io/material-ui-kit

Version:
20 lines 1.12 kB
import _extends from "@babel/runtime/helpers/extends";import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";import React from "react"; import { useHistory, useLocation } from "react-router-dom"; import LeaveGuard from "./LeaveGuard"; var RouteLeavingGuard = function RouteLeavingGuard(props) {var _props$when = props.when,when = _props$when === void 0 ? true : _props$when,children = props.children,otherProps = _objectWithoutProperties(props, ["when", "children"]); var history = useHistory();var _useLocation = useLocation(),pathname = _useLocation.pathname; return /*#__PURE__*/React.createElement(React.Fragment, null, children, /*#__PURE__*/ React.createElement(LeaveGuard, _extends({ pathname: pathname }, otherProps, { when: when, navigate: function navigate(path) {return history.push(path);}, shouldBlockNavigation: function shouldBlockNavigation(location) { if (when) { if (location.pathname !== pathname) { return true; } } return false; } }))); }; export default RouteLeavingGuard; //# sourceMappingURL=index.js.map