UNPKG

router-guard

Version:

A higher-order component for react-router v4 that implements routing guards

10 lines (8 loc) 3.07 kB
/** * Bundle of router-guard * Generated: 2020-04-08 * Version: 2.0.0 * License: MIT * Author: 2631541504@qq.com */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e((t=t||self).RouterGuard={},t.React)}(this,function(i,a){"use strict";function s(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(t){return(n="function"==typeof Symbol&&"symbol"===e(Symbol.iterator)?function(t){return e(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":e(t)})(t)}function c(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function f(t){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function l(t,e){return(l=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var t;function p(t){var e=t.pathname,n=void 0===e?"/":e,o=t.search,r=void 0===o?"":o,u=t.hash;return n+r+(void 0===u?"":u)}function y(e,o){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:y.guard,u=3<arguments.length&&void 0!==arguments[3]?arguments[3]:y.pendingPlaceholder;return r?function(){function n(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),(e=c(this,f(n).call(this,t))).state={status:i.Status.Pending},e.$isNextCalled=!1,e.$isMounted=!1,r(Object.assign({},t,{meta:o||{}}),e.next(function(t){e.$isMounted?e.setState(t):e.state=t})),e}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&l(t,e)}(n,a.Component),function(t,e,n){e&&s(t.prototype,e),n&&s(t,n)}(n,[{key:"componentDidMount",value:function(){this.$isMounted=!0}},{key:"next",value:function(t){var n=this,o=t||this.setState.bind(this);return function(t,e){n.$isNextCalled||(!t||function(t,e){return"string"==typeof t?t===p(e):p(t)===p(e)}(t,n.props.location)?o({status:i.Status.Resolved}):e?n.props.history.replace(t):n.props.history.push(t),n.$isNextCalled=!0)}}},{key:"render",value:function(){var t=this.props;return this.state.status===i.Status.Pending?u&&u(t,o):e?a.createElement(e,t):a.createElement(a.Fragment,null)}}]),n}():e}a=a&&a.hasOwnProperty("default")?a.default:a,(t=i.Status||(i.Status={}))[t.Pending=0]="Pending",t[t.Resolved=1]="Resolved",y.guard=null,y.pendingPlaceholder=null,i.RouterGuard=y,Object.defineProperty(i,"__esModule",{value:!0})});