UNPKG

react-router-dom

Version:

Declarative routing for React web applications

35 lines (34 loc) • 16.7 kB
'use strict';(function(e,n){"object"===typeof exports&&"undefined"!==typeof module?n(exports,require("react"),require("history"),require("react-router")):"function"===typeof define&&define.amd?define(["exports","react","history","react-router"],n):(e=e||self,n(e.ReactRouterDOM={},e.React,e.HistoryLibrary,e.ReactRouter))})(this,function(e,n,I,h){function v(){v=Object.assign||function(a){for(var c=1;c<arguments.length;c++){var p=arguments[c],g;for(g in p)Object.prototype.hasOwnProperty.call(p,g)&&(a[g]= p[g])}return a};return v.apply(this,arguments)}function J(a,c){if(null==a)return{};var p={},g=Object.keys(a),f;for(f=0;f<g.length;f++){var l=g[f];0<=c.indexOf(l)||(p[l]=a[l])}return p}function u(a,c){return c={exports:{}},a(c,c.exports),c.exports}function B(a,c,p,g,f){for(var l in a)if(O(a,l)){try{if("function"!==typeof a[l]){var e=Error((g||"React class")+": "+p+" type `"+l+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof a[l]+"`.");e.name="Invariant Violation"; throw e;}var m=a[l](c,l,g,p,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(P){m=P}!m||m instanceof Error||C((g||"React class")+": type specification of "+p+" `"+l+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof m+". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).");if(m instanceof Error&&!(m.message in D)){D[m.message]=!0;var d= f?f():"";C("Failed "+p+" type: "+m.message+(null!=d?d:""))}}}function x(){return null}function E(a){var c=a.children,p=a.timeout;a=a.window;var g=n.useRef(null);null==g.current&&(g.current=I.createBrowserHistory({window:a}));return n.createElement(h.Router,{children:c,history:g.current,timeout:p})}function F(a){var c=a.children,p=a.timeout;a=a.window;var g=n.useRef(null);null==g.current&&(g.current=I.createHashHistory({window:a}));return n.createElement(h.Router,{children:c,history:g.current,timeout:p})} function G(a){K(a.message,a.when);return null}function K(a,c){var p=n.useCallback(function(g){window.confirm(a)&&g.retry()},[a]);h.useBlocker(p,c)}n=n&&n.hasOwnProperty("default")?n["default"]:n;var L=u(function(a,c){(function(){function a(a){if("object"===typeof a&&null!==a){var g=a.$$typeof;switch(g){case l:switch(a=a.type,a){case b:case k:case m:case h:case d:case y:return a;default:switch(a=a&&a.$$typeof,a){case r:case w:case z:case A:case n:return a;default:return g}}case e:return g}}}function g(b){return a(b)=== k}Object.defineProperty(c,"__esModule",{value:!0});var f="function"===typeof Symbol&&Symbol.for,l=f?Symbol.for("react.element"):60103,e=f?Symbol.for("react.portal"):60106,m=f?Symbol.for("react.fragment"):60107,d=f?Symbol.for("react.strict_mode"):60108,h=f?Symbol.for("react.profiler"):60114,n=f?Symbol.for("react.provider"):60109,r=f?Symbol.for("react.context"):60110,b=f?Symbol.for("react.async_mode"):60111,k=f?Symbol.for("react.concurrent_mode"):60111,w=f?Symbol.for("react.forward_ref"):60112,y=f? Symbol.for("react.suspense"):60113,Q=f?Symbol.for("react.suspense_list"):60120,A=f?Symbol.for("react.memo"):60115,z=f?Symbol.for("react.lazy"):60116,R=f?Symbol.for("react.fundamental"):60117,S=f?Symbol.for("react.responder"):60118,v=f?Symbol.for("react.scope"):60119;f=function(){};var T=function(a){for(var b=arguments.length,k=Array(1<b?b-1:0),g=1;g<b;g++)k[g-1]=arguments[g];var c=0;b="Warning: "+a.replace(/%s/g,function(){return k[c++]});"undefined"!==typeof console&&console.warn(b);try{throw Error(b); }catch(Z){}},q=f=function(b,a){if(void 0===a)throw Error("`lowPriorityWarningWithoutStack(condition, format, ...args)` requires a warning message argument");if(!b){for(var k=arguments.length,g=Array(2<k?k-2:0),c=2;c<k;c++)g[c-2]=arguments[c];T.apply(void 0,[a].concat(g))}},t=!1;c.typeOf=a;c.AsyncMode=b;c.ConcurrentMode=k;c.ContextConsumer=r;c.ContextProvider=n;c.Element=l;c.ForwardRef=w;c.Fragment=m;c.Lazy=z;c.Memo=A;c.Portal=e;c.Profiler=h;c.StrictMode=d;c.Suspense=y;c.isValidElementType=function(a){return"string"=== typeof a||"function"===typeof a||a===m||a===k||a===h||a===d||a===y||a===Q||"object"===typeof a&&null!==a&&(a.$$typeof===z||a.$$typeof===A||a.$$typeof===n||a.$$typeof===r||a.$$typeof===w||a.$$typeof===R||a.$$typeof===S||a.$$typeof===v)};c.isAsyncMode=function(k){t||(t=!0,q(!1,"The ReactIs.isAsyncMode() alias has been deprecated, and will be removed in React 17+. Update your code to use ReactIs.isConcurrentMode() instead. It has the exact same API."));return g(k)||a(k)===b};c.isConcurrentMode=g;c.isContextConsumer= function(b){return a(b)===r};c.isContextProvider=function(b){return a(b)===n};c.isElement=function(a){return"object"===typeof a&&null!==a&&a.$$typeof===l};c.isForwardRef=function(b){return a(b)===w};c.isFragment=function(b){return a(b)===m};c.isLazy=function(b){return a(b)===z};c.isMemo=function(b){return a(b)===A};c.isPortal=function(b){return a(b)===e};c.isProfiler=function(b){return a(b)===h};c.isStrictMode=function(b){return a(b)===d};c.isSuspense=function(b){return a(b)===y}})()});(function(a){return a&& a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a["default"]:a})(L);var M=u(function(a){a.exports=L}),N=Object.getOwnPropertySymbols,U=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable,W=function(){try{if(!Object.assign)return!1;var a=new String("abc");a[5]="de";if("5"===Object.getOwnPropertyNames(a)[0])return!1;var c={};for(a=0;10>a;a++)c["_"+String.fromCharCode(a)]=a;if("0123456789"!==Object.getOwnPropertyNames(c).map(function(a){return c[a]}).join(""))return!1; var e={};"abcdefghijklmnopqrst".split("").forEach(function(a){e[a]=a});return"abcdefghijklmnopqrst"!==Object.keys(Object.assign({},e)).join("")?!1:!0}catch(g){return!1}}()?Object.assign:function(a,c){if(null===a||void 0===a)throw new TypeError("Object.assign cannot be called with null or undefined");var e=Object(a);for(var g,f=1;f<arguments.length;f++){var l=Object(arguments[f]);for(var d in l)U.call(l,d)&&(e[d]=l[d]);if(N){g=N(l);for(var m=0;m<g.length;m++)V.call(l,g[m])&&(e[g[m]]=l[g[m]])}}return e}, C=function(){},D={},O=Function.call.bind(Object.prototype.hasOwnProperty);C=function(a){a="Warning: "+a;"undefined"!==typeof console&&console.error(a);try{throw Error(a);}catch(c){}};B.resetWarningCache=function(){D={}};var X=Function.call.bind(Object.prototype.hasOwnProperty),q=function(){};q=function(a){a="Warning: "+a;"undefined"!==typeof console&&console.error(a);try{throw Error(a);}catch(c){}};var Y=function(a,c){function e(a,k){return a===k?0!==a||1/a===1/k:a!==a&&k!==k}function g(a){this.message= a;this.stack=""}function f(a){function b(b,k,e,d,h,m,l){d=d||"<<anonymous>>";m=m||e;if("SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"!==l){if(c)throw b=Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them. Read more at http://fb.me/use-check-prop-types"),b.name="Invariant Violation",b;"undefined"!==typeof console&&(l=d+":"+e,!w[l]&&3>f&&(q("You are manually calling a React.PropTypes validation function for the `"+ m+"` prop on `"+d+"`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details."),w[l]=!0,f++))}return null==k[e]?b?null===k[e]?new g("The "+h+" `"+m+"` is marked as required in `"+(d+"`, but its value is `null`.")):new g("The "+h+" `"+m+"` is marked as required in `"+(d+"`, but its value is `undefined`.")):null:a(k,e,d,h,m)}var w={},f=0,e=b.bind(null, !1);e.isRequired=b.bind(null,!0);return e}function d(a){return f(function(b,c,e,f,d,h){b=b[c];return m(b)!==a?(b=n(b),new g("Invalid "+f+" `"+d+"` of type `"+(b+"` supplied to `"+e+"`, expected `")+(a+"`."))):null})}function h(b){switch(typeof b){case "number":case "string":case "undefined":return!0;case "boolean":return!b;case "object":if(Array.isArray(b))return b.every(h);if(null===b||a(b))return!0;var k=b&&(t&&b[t]||b["@@iterator"]);var g="function"===typeof k?k:void 0;if(g)if(k=g.call(b),g!== b.entries)for(;!(b=k.next()).done;){if(!h(b.value))return!1}else for(;!(b=k.next()).done;){if((b=b.value)&&!h(b[1]))return!1}else return!1;return!0;default:return!1}}function m(a){var b=typeof a;return Array.isArray(a)?"array":a instanceof RegExp?"object":"symbol"===b||a&&("Symbol"===a["@@toStringTag"]||"function"===typeof Symbol&&a instanceof Symbol)?"symbol":b}function n(a){if("undefined"===typeof a||null===a)return""+a;var b=m(a);if("object"===b){if(a instanceof Date)return"date";if(a instanceof RegExp)return"regexp"}return b}function v(a){a=n(a);switch(a){case "array":case "object":return"an "+a;case "boolean":case "date":case "regexp":return"a "+a;default:return a}}var t="function"===typeof Symbol&&Symbol.iterator,r={array:d("array"),bool:d("boolean"),func:d("function"),number:d("number"),object:d("object"),string:d("string"),symbol:d("symbol"),any:f(x),arrayOf:function(a){return f(function(b,c,e,f,d){if("function"!==typeof a)return new g("Property `"+d+"` of component `"+e+"` has invalid PropType notation inside arrayOf."); b=b[c];if(!Array.isArray(b))return b=m(b),new g("Invalid "+f+" `"+d+"` of type `"+(b+"` supplied to `"+e+"`, expected an array."));for(c=0;c<b.length;c++){var k=a(b,c,e,f,d+"["+c+"]","SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");if(k instanceof Error)return k}return null})},element:function(){return f(function(b,c,e,f,d){b=b[c];return a(b)?null:(b=m(b),new g("Invalid "+f+" `"+d+"` of type `"+(b+"` supplied to `"+e+"`, expected a single ReactElement.")))})}(),elementType:function(){return f(function(a, c,e,f,d){a=a[c];return M.isValidElementType(a)?null:(a=m(a),new g("Invalid "+f+" `"+d+"` of type `"+(a+"` supplied to `"+e+"`, expected a single ReactElement type.")))})}(),instanceOf:function(a){return f(function(b,c,e,f,d){if(!(b[c]instanceof a)){var k=a.name||"<<anonymous>>";b=b[c];b=b.constructor&&b.constructor.name?b.constructor.name:"<<anonymous>>";return new g("Invalid "+f+" `"+d+"` of type `"+(b+"` supplied to `"+e+"`, expected instance of `")+(k+"`."))}return null})},node:function(){return f(function(a, c,e,f,d){return h(a[c])?null:new g("Invalid "+f+" `"+d+"` supplied to `"+(e+"`, expected a ReactNode."))})}(),objectOf:function(a){return f(function(b,c,e,f,d){if("function"!==typeof a)return new g("Property `"+d+"` of component `"+e+"` has invalid PropType notation inside objectOf.");b=b[c];c=m(b);if("object"!==c)return new g("Invalid "+f+" `"+d+"` of type `"+(c+"` supplied to `"+e+"`, expected an object."));for(var k in b)if(X(b,k)&&(c=a(b,k,e,f,d+"."+k,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"), c instanceof Error))return c;return null})},oneOf:function(a){return Array.isArray(a)?f(function(b,c,d,f,h){b=b[c];for(c=0;c<a.length;c++)if(e(b,a[c]))return null;c=JSON.stringify(a,function(a,b){return"symbol"===n(b)?String(b):b});return new g("Invalid "+f+" `"+h+"` of value `"+String(b)+"` supplied to `"+(d+"`, expected one of "+c+"."))}):(1<arguments.length?q("Invalid arguments supplied to oneOf, expected an array, got "+arguments.length+" arguments. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z])."): q("Invalid argument supplied to oneOf, expected an array."),x)},oneOfType:function(a){if(!Array.isArray(a))return q("Invalid argument supplied to oneOfType, expected an instance of array."),x;for(var b=0;b<a.length;b++){var c=a[b];if("function"!==typeof c)return q("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+v(c)+" at index "+b+"."),x}return f(function(b,c,d,e,f){for(var k=0;k<a.length;k++)if(null==(0,a[k])(b,c,d,e,f,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"))return null; return new g("Invalid "+e+" `"+f+"` supplied to `"+(d+"`."))})},shape:function(a){return f(function(b,c,d,e,f){b=b[c];c=m(b);if("object"!==c)return new g("Invalid "+e+" `"+f+"` of type `"+c+"` supplied to `"+(d+"`, expected `object`."));for(var k in a)if(c=a[k])if(c=c(b,k,d,e,f+"."+k,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"))return c;return null})},exact:function(a){return f(function(b,c,d,e,f){var k=b[c],h=m(k);if("object"!==h)return new g("Invalid "+e+" `"+f+"` of type `"+h+"` supplied to `"+ (d+"`, expected `object`."));h=W({},b[c],a);for(var l in h){h=a[l];if(!h)return new g("Invalid "+e+" `"+f+"` key `"+l+"` supplied to `"+d+"`.\nBad object: "+JSON.stringify(b[c],null," ")+"\nValid keys: "+JSON.stringify(Object.keys(a),null," "));if(h=h(k,l,d,e,f+"."+l,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"))return h}return null})}};g.prototype=Error.prototype;r.checkPropTypes=B;r.resetWarningCache=B.resetWarningCache;return r.PropTypes=r},d=u(function(a){a.exports=Y(M.isElement,!0)});E.displayName= "BrowserRouter";E.propTypes={children:d.node,timeout:d.number,window:d.object};F.displayName="HashRouter";F.propTypes={children:d.node,timeout:d.number,window:d.object};var t=n.forwardRef(function(a,c){var d=a.as;d=void 0===d?"a":d;var e=a.onClick,f=a.replace,l=void 0===f?!1:f,t=a.state,m=a.target,q=a.to;a=J(a,"as onClick replace state target to".split(" "));f=h.useHref(q);var x=h.useNavigate(),u=h.useLocation(),r=h.useResolvedLocation(q);return n.createElement(d,v({},a,{href:f,onClick:function(a){e&& e(a);a.defaultPrevented||0!==a.button||m&&"_self"!==m||a.metaKey||a.altKey||a.ctrlKey||a.shiftKey||(a.preventDefault(),a=r.pathname===u.pathname&&r.search===u.search&&r.hash===u.hash,x(q,{replace:!!l||a,state:t}))},ref:c,target:m}))});t.displayName="Link";t.propTypes={as:d.elementType,onClick:d.func,replace:d.bool,state:d.object,target:d.string,to:d.oneOfType([d.string,d.shape({pathname:d.string,search:d.string,hash:d.string})]).isRequired};var H=n.forwardRef(function(a,c){var d=a["aria-current"]; d=void 0===d?"page":d;var e=a.activeClassName;e=void 0===e?"active":e;var f=a.activeStyle;f=void 0===f?null:f;var l=a.className,q=void 0===l?"":l;l=a.style;var m=void 0===l?null:l;l=a.to;a=J(a,"aria-current activeClassName activeStyle className style to".split(" "));var u=h.useMatch(l);d=u?d:void 0;e=[q,u?e:null].filter(Boolean).join(" ");f=v({},m,{},u?f:null);return n.createElement(t,v({},a,{"aria-current":d,className:e,ref:c,style:f,to:l}))});H.displayName="NavLink";H.propTypes=v({},t.propTypes, {"aria-current":d.oneOf("page step location date time true".split(" ")),activeClassName:d.string,activeStyle:d.object,className:d.string,style:d.object,to:d.oneOfType([d.string,d.shape({pathname:d.string,search:d.string,hash:d.string})]).isRequired});G.displayName="Prompt";G.propTypes={message:d.string,when:d.bool};Object.defineProperty(e,"MemoryRouter",{enumerable:!0,get:function(){return h.MemoryRouter}});Object.defineProperty(e,"Navigate",{enumerable:!0,get:function(){return h.Navigate}});Object.defineProperty(e, "Outlet",{enumerable:!0,get:function(){return h.Outlet}});Object.defineProperty(e,"Redirect",{enumerable:!0,get:function(){return h.Redirect}});Object.defineProperty(e,"Route",{enumerable:!0,get:function(){return h.Route}});Object.defineProperty(e,"Router",{enumerable:!0,get:function(){return h.Router}});Object.defineProperty(e,"Routes",{enumerable:!0,get:function(){return h.Routes}});Object.defineProperty(e,"createRoutesFromChildren",{enumerable:!0,get:function(){return h.createRoutesFromChildren}}); Object.defineProperty(e,"generatePath",{enumerable:!0,get:function(){return h.generatePath}});Object.defineProperty(e,"matchRoutes",{enumerable:!0,get:function(){return h.matchRoutes}});Object.defineProperty(e,"resolveLocation",{enumerable:!0,get:function(){return h.resolveLocation}});Object.defineProperty(e,"useBlocker",{enumerable:!0,get:function(){return h.useBlocker}});Object.defineProperty(e,"useHref",{enumerable:!0,get:function(){return h.useHref}});Object.defineProperty(e,"useLocation",{enumerable:!0, get:function(){return h.useLocation}});Object.defineProperty(e,"useMatch",{enumerable:!0,get:function(){return h.useMatch}});Object.defineProperty(e,"useNavigate",{enumerable:!0,get:function(){return h.useNavigate}});Object.defineProperty(e,"useOutlet",{enumerable:!0,get:function(){return h.useOutlet}});Object.defineProperty(e,"useParams",{enumerable:!0,get:function(){return h.useParams}});Object.defineProperty(e,"useResolvedLocation",{enumerable:!0,get:function(){return h.useResolvedLocation}}); Object.defineProperty(e,"useRoutes",{enumerable:!0,get:function(){return h.useRoutes}});e.BrowserRouter=E;e.HashRouter=F;e.Link=t;e.NavLink=H;e.Prompt=G;e.usePrompt=K;Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=react-router-dom.development.js.map