UNPKG

react-router-dom

Version:

Declarative routing for React web applications

38 lines (37 loc) • 18.8 kB
'use strict';(function(d,m){"object"===typeof exports&&"undefined"!==typeof module?m(exports,require("react"),require("history"),require("react-router")):"function"===typeof define&&define.amd?define(["exports","react","history","react-router"],m):(d=d||self,m(d.ReactRouterDOM={},d.React,d.HistoryLibrary,d.ReactRouter))})(this,function(d,m,x,g){function y(){y=Object.assign||function(a){for(var b=1;b<arguments.length;b++){var c=arguments[b],h;for(h in c)Object.prototype.hasOwnProperty.call(c,h)&&(a[h]= c[h])}return a};return y.apply(this,arguments)}function M(a,b){if(null==a)return{};var c={},h=Object.keys(a),e;for(e=0;e<h.length;e++){var l=h[e];0<=b.indexOf(l)||(c[l]=a[l])}return c}function S(a,b){if(a){if("string"===typeof a)return N(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);"Object"===c&&a.constructor&&(c=a.constructor.name);if("Map"===c||"Set"===c)return Array.from(c);if("Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c))return N(a,b)}}function N(a,b){if(null== b||b>a.length)b=a.length;for(var c=0,h=Array(b);c<b;c++)h[c]=a[c];return h}function T(a){var b=0;if("undefined"===typeof Symbol||null==a[Symbol.iterator]){if(Array.isArray(a)||(a=S(a)))return function(){return b>=a.length?{done:!0}:{done:!1,value:a[b++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}b=a[Symbol.iterator]();return b.next.bind(b)}function E(a,b){return b={exports:{}},a(b, b.exports),b.exports}function F(a,b,c,h,e){for(var l in a)if(U(a,l)){try{if("function"!==typeof a[l]){var d=Error((h||"React class")+": "+c+" type `"+l+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof a[l]+"`.");d.name="Invariant Violation";throw d;}var q=a[l](b,l,h,c,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(v){q=v}!q||q instanceof Error||G((h||"React class")+": type specification of "+c+" `"+l+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+ typeof q+". 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(q instanceof Error&&!(q.message in H)){H[q.message]=!0;var g=e?e():"";G("Failed "+c+" type: "+q.message+(null!=g?g:""))}}}function z(){return null}function V(a,b){if(!a){"undefined"!==typeof console&&console.warn(b);try{throw Error(b);}catch(c){}}}function I(a){var b=a.children;a=a.window;var c=m.useRef();null==c.current&&(c.current= x.createBrowserHistory({window:a}));var h=c.current;a=m.useReducer(function(a,b){return b},{action:h.action,location:h.location});c=a[0];var e=a[1];m.useLayoutEffect(function(){return h.listen(e)},[h]);return m.createElement(g.Router,{children:b,action:c.action,location:c.location,navigator:h})}function J(a){var b=a.children;a=a.window;var c=m.useRef();null==c.current&&(c.current=x.createHashHistory({window:a}));var h=c.current;a=m.useReducer(function(a,b){return b},{action:h.action,location:h.location}); c=a[0];var e=a[1];m.useLayoutEffect(function(){return h.listen(e)},[h]);return m.createElement(g.Router,{children:b,action:c.action,location:c.location,navigator:h})}function K(a){O(a.message,a.when);return null}function O(a,b){void 0===b&&(b=!0);var c=m.useCallback(function(b){window.confirm(a)&&b.retry()},[a]);g.useBlocker(c,b)}function A(a){void 0===a&&(a="");return new URLSearchParams("string"===typeof a||Array.isArray(a)||a instanceof URLSearchParams?a:Object.keys(a).reduce(function(b,c){var h= a[c];return b.concat(Array.isArray(h)?h.map(function(a){return[c,a]}):[[c,h]])},[]))}var aa=E(function(a,b){(function(){function a(a){if("object"===typeof a&&null!==a){var b=a.$$typeof;switch(b){case l:switch(a=a.type,a){case f:case u:case g:case m:case k:case B:return a;default:switch(a=a&&a.$$typeof,a){case n:case r:case C:case D:case p:return a;default:return b}}case d:return b}}}function h(f){return a(f)===u}var e="function"===typeof Symbol&&Symbol.for,l=e?Symbol.for("react.element"):60103,d= e?Symbol.for("react.portal"):60106,g=e?Symbol.for("react.fragment"):60107,k=e?Symbol.for("react.strict_mode"):60108,m=e?Symbol.for("react.profiler"):60114,p=e?Symbol.for("react.provider"):60109,n=e?Symbol.for("react.context"):60110,f=e?Symbol.for("react.async_mode"):60111,u=e?Symbol.for("react.concurrent_mode"):60111,r=e?Symbol.for("react.forward_ref"):60112,B=e?Symbol.for("react.suspense"):60113,W=e?Symbol.for("react.suspense_list"):60120,D=e?Symbol.for("react.memo"):60115,C=e?Symbol.for("react.lazy"): 60116,X=e?Symbol.for("react.block"):60121,Y=e?Symbol.for("react.fundamental"):60117,t=e?Symbol.for("react.responder"):60118,Z=e?Symbol.for("react.scope"):60119,P=!1;b.AsyncMode=f;b.ConcurrentMode=u;b.ContextConsumer=n;b.ContextProvider=p;b.Element=l;b.ForwardRef=r;b.Fragment=g;b.Lazy=C;b.Memo=D;b.Portal=d;b.Profiler=m;b.StrictMode=k;b.Suspense=B;b.isAsyncMode=function(b){P||(P=!0,console.warn("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 h(b)||a(b)===f};b.isConcurrentMode=h;b.isContextConsumer=function(f){return a(f)===n};b.isContextProvider=function(f){return a(f)===p};b.isElement=function(a){return"object"===typeof a&&null!==a&&a.$$typeof===l};b.isForwardRef=function(f){return a(f)===r};b.isFragment=function(f){return a(f)===g};b.isLazy=function(f){return a(f)===C};b.isMemo=function(f){return a(f)===D};b.isPortal=function(f){return a(f)===d};b.isProfiler=function(f){return a(f)===m};b.isStrictMode=function(f){return a(f)=== k};b.isSuspense=function(f){return a(f)===B};b.isValidElementType=function(a){return"string"===typeof a||"function"===typeof a||a===g||a===u||a===m||a===k||a===B||a===W||"object"===typeof a&&null!==a&&(a.$$typeof===C||a.$$typeof===D||a.$$typeof===p||a.$$typeof===n||a.$$typeof===r||a.$$typeof===Y||a.$$typeof===t||a.$$typeof===Z||a.$$typeof===X)};b.typeOf=a})()}),Q=E(function(a){a.exports=aa}),R=Object.getOwnPropertySymbols,ba=Object.prototype.hasOwnProperty,ca=Object.prototype.propertyIsEnumerable, da=function(){try{if(!Object.assign)return!1;var a=new String("abc");a[5]="de";if("5"===Object.getOwnPropertyNames(a)[0])return!1;var b={};for(a=0;10>a;a++)b["_"+String.fromCharCode(a)]=a;if("0123456789"!==Object.getOwnPropertyNames(b).map(function(a){return b[a]}).join(""))return!1;var c={};"abcdefghijklmnopqrst".split("").forEach(function(a){c[a]=a});return"abcdefghijklmnopqrst"!==Object.keys(Object.assign({},c)).join("")?!1:!0}catch(h){return!1}}()?Object.assign:function(a,b){if(null===a||void 0=== a)throw new TypeError("Object.assign cannot be called with null or undefined");var c=Object(a);for(var h,e=1;e<arguments.length;e++){var l=Object(arguments[e]);for(var d in l)ba.call(l,d)&&(c[d]=l[d]);if(R){h=R(l);for(var g=0;g<h.length;g++)ca.call(l,h[g])&&(c[h[g]]=l[h[g]])}}return c},G=function(){},H={},U=Function.call.bind(Object.prototype.hasOwnProperty);G=function(a){a="Warning: "+a;"undefined"!==typeof console&&console.error(a);try{throw Error(a);}catch(b){}};F.resetWarningCache=function(){H= {}};var ea=Function.call.bind(Object.prototype.hasOwnProperty),t=function(){};t=function(a){a="Warning: "+a;"undefined"!==typeof console&&console.error(a);try{throw Error(a);}catch(b){}};var fa=function(a,b){function c(a,b){return a===b?0!==a||1/a===1/b:a!==a&&b!==b}function h(a){this.message=a;this.stack=""}function e(a){function f(f,u,e,r,g,l,k){r=r||"<<anonymous>>";l=l||e;if("SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"!==k){if(b)throw f=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"), f.name="Invariant Violation",f;"undefined"!==typeof console&&(k=r+":"+e,!c[k]&&3>d&&(t("You are manually calling a React.PropTypes validation function for the `"+l+"` prop on `"+r+"`. 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."),c[k]=!0,d++))}return null==u[e]?f?null===u[e]?new h("The "+g+" `"+l+"` is marked as required in `"+(r+"`, but its value is `null`.")): new h("The "+g+" `"+l+"` is marked as required in `"+(r+"`, but its value is `undefined`.")):null:a(u,e,r,g,l)}var c={},d=0,e=f.bind(null,!1);e.isRequired=f.bind(null,!0);return e}function d(a){return e(function(f,b,c,e,d,g){f=f[b];return k(f)!==a?(f=m(f),new h("Invalid "+e+" `"+d+"` of type `"+(f+"` supplied to `"+c+"`, expected `")+(a+"`."))):null})}function g(f){switch(typeof f){case "number":case "string":case "undefined":return!0;case "boolean":return!f;case "object":if(Array.isArray(f))return f.every(g); if(null===f||a(f))return!0;var b=f&&(p&&f[p]||f["@@iterator"]);var c="function"===typeof b?b:void 0;if(c)if(b=c.call(f),c!==f.entries)for(;!(f=b.next()).done;){if(!g(f.value))return!1}else for(;!(f=b.next()).done;){if((f=f.value)&&!g(f[1]))return!1}else return!1;return!0;default:return!1}}function k(a){var f=typeof a;return Array.isArray(a)?"array":a instanceof RegExp?"object":"symbol"===f||a&&("Symbol"===a["@@toStringTag"]||"function"===typeof Symbol&&a instanceof Symbol)?"symbol":f}function m(a){if("undefined"=== typeof a||null===a)return""+a;var b=k(a);if("object"===b){if(a instanceof Date)return"date";if(a instanceof RegExp)return"regexp"}return b}function v(a){a=m(a);switch(a){case "array":case "object":return"an "+a;case "boolean":case "date":case "regexp":return"a "+a;default:return a}}var p="function"===typeof Symbol&&Symbol.iterator,n={array:d("array"),bool:d("boolean"),func:d("function"),number:d("number"),object:d("object"),string:d("string"),symbol:d("symbol"),any:e(z),arrayOf:function(a){return e(function(b, f,c,e,d){if("function"!==typeof a)return new h("Property `"+d+"` of component `"+c+"` has invalid PropType notation inside arrayOf.");b=b[f];if(!Array.isArray(b))return b=k(b),new h("Invalid "+e+" `"+d+"` of type `"+(b+"` supplied to `"+c+"`, expected an array."));for(f=0;f<b.length;f++){var g=a(b,f,c,e,d+"["+f+"]","SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");if(g instanceof Error)return g}return null})},element:function(){return e(function(b,c,e,d,g){b=b[c];return a(b)?null:(b=k(b),new h("Invalid "+ d+" `"+g+"` of type `"+(b+"` supplied to `"+e+"`, expected a single ReactElement.")))})}(),elementType:function(){return e(function(a,b,c,e,d){a=a[b];return Q.isValidElementType(a)?null:(a=k(a),new h("Invalid "+e+" `"+d+"` of type `"+(a+"` supplied to `"+c+"`, expected a single ReactElement type.")))})}(),instanceOf:function(a){return e(function(b,f,c,e,d){if(!(b[f]instanceof a)){var g=a.name||"<<anonymous>>";b=b[f];b=b.constructor&&b.constructor.name?b.constructor.name:"<<anonymous>>";return new h("Invalid "+ e+" `"+d+"` of type `"+(b+"` supplied to `"+c+"`, expected instance of `")+(g+"`."))}return null})},node:function(){return e(function(a,b,c,e,d){return g(a[b])?null:new h("Invalid "+e+" `"+d+"` supplied to `"+(c+"`, expected a ReactNode."))})}(),objectOf:function(a){return e(function(b,c,f,e,d){if("function"!==typeof a)return new h("Property `"+d+"` of component `"+f+"` has invalid PropType notation inside objectOf.");b=b[c];c=k(b);if("object"!==c)return new h("Invalid "+e+" `"+d+"` of type `"+(c+ "` supplied to `"+f+"`, expected an object."));for(var g in b)if(ea(b,g)&&(c=a(b,g,f,e,d+"."+g,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"),c instanceof Error))return c;return null})},oneOf:function(a){return Array.isArray(a)?e(function(b,f,e,d,g){b=b[f];for(f=0;f<a.length;f++)if(c(b,a[f]))return null;f=JSON.stringify(a,function(a,b){return"symbol"===m(b)?String(b):b});return new h("Invalid "+d+" `"+g+"` of value `"+String(b)+"` supplied to `"+(e+"`, expected one of "+f+"."))}):(1<arguments.length? t("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])."):t("Invalid argument supplied to oneOf, expected an array."),z)},oneOfType:function(a){if(!Array.isArray(a))return t("Invalid argument supplied to oneOfType, expected an instance of array."),z;for(var b=0;b<a.length;b++){var c=a[b];if("function"!==typeof c)return t("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+ v(c)+" at index "+b+"."),z}return e(function(b,c,f,e,d){for(var g=0;g<a.length;g++)if(null==(0,a[g])(b,c,f,e,d,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"))return null;return new h("Invalid "+e+" `"+d+"` supplied to `"+(f+"`."))})},shape:function(a){return e(function(b,c,f,e,d){b=b[c];c=k(b);if("object"!==c)return new h("Invalid "+e+" `"+d+"` of type `"+c+"` supplied to `"+(f+"`, expected `object`."));for(var g in a)if(c=a[g])if(c=c(b,g,f,e,d+"."+g,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"))return c; return null})},exact:function(a){return e(function(b,c,f,e,d){var g=b[c],l=k(g);if("object"!==l)return new h("Invalid "+e+" `"+d+"` of type `"+l+"` supplied to `"+(f+"`, expected `object`."));l=da({},b[c],a);for(var m in l){l=a[m];if(!l)return new h("Invalid "+e+" `"+d+"` key `"+m+"` supplied to `"+f+"`.\nBad object: "+JSON.stringify(b[c],null," ")+"\nValid keys: "+JSON.stringify(Object.keys(a),null," "));if(l=l(g,m,f,e,d+"."+m,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"))return l}return null})}}; h.prototype=Error.prototype;n.checkPropTypes=F;n.resetWarningCache=F.resetWarningCache;return n.PropTypes=n},k=E(function(a){a.exports=fa(Q.isElement,!0)});I.displayName="BrowserRouter";I.propTypes={children:k.node,window:k.object};J.displayName="HashRouter";J.propTypes={children:k.node,window:k.object};var w=m.forwardRef(function(a,b){var c=a.onClick,d=a.replace,e=void 0===d?!1:d,l=a.state,k=a.target,q=a.to;a=M(a,["onClick","replace","state","target","to"]);d=g.useHref(q);var t=g.useNavigate(),v= g.useLocation(),p=g.useResolvedLocation(q);return m.createElement("a",Object.assign({},a,{href:d,onClick:function(a){c&&c(a);a.defaultPrevented||0!==a.button||k&&"_self"!==k||a.metaKey||a.altKey||a.ctrlKey||a.shiftKey||(a.preventDefault(),a=!!e||x.createPath(v)===x.createPath(p),t(q,{replace:a,state:l}))},ref:b,target:k}))});w.displayName="Link";w.propTypes={onClick:k.func,replace:k.bool,state:k.object,target:k.string,to:k.oneOfType([k.string,k.shape({pathname:k.string,search:k.string,hash:k.string})]).isRequired}; var L=m.forwardRef(function(a,b){var c=a["aria-current"],d=void 0===c?"page":c;c=a.activeClassName;var e=void 0===c?"active":c;c=a.activeStyle;var l=a.caseSensitive,k=void 0===l?!1:l;l=a.className;var q=void 0===l?"":l;l=a.end;var t=void 0===l?!1:l,v=a.style;l=a.to;a=M(a,"aria-current activeClassName activeStyle caseSensitive className end style to".split(" "));var p=g.useLocation(),n=g.useResolvedLocation(l);p=p.pathname;n=n.pathname;k||(p=p.toLowerCase(),n=n.toLowerCase());d=(k=t?p===n:p.startsWith(n))? d:void 0;e=[q,k?e:null].filter(Boolean).join(" ");c=y({},v,{},k?c:null);return m.createElement(w,Object.assign({},a,{"aria-current":d,className:e,ref:b,style:c,to:l}))});L.displayName="NavLink";L.propTypes=y({},w.propTypes,{"aria-current":k.oneOf("page step location date time true".split(" ")),activeClassName:k.string,activeStyle:k.object,className:k.string,style:k.object,to:k.oneOfType([k.string,k.shape({pathname:k.string,search:k.string,hash:k.string})]).isRequired});K.displayName="Prompt";K.propTypes= {message:k.string,when:k.bool};Object.defineProperty(d,"MemoryRouter",{enumerable:!0,get:function(){return g.MemoryRouter}});Object.defineProperty(d,"Navigate",{enumerable:!0,get:function(){return g.Navigate}});Object.defineProperty(d,"Outlet",{enumerable:!0,get:function(){return g.Outlet}});Object.defineProperty(d,"Route",{enumerable:!0,get:function(){return g.Route}});Object.defineProperty(d,"Router",{enumerable:!0,get:function(){return g.Router}});Object.defineProperty(d,"Routes",{enumerable:!0, get:function(){return g.Routes}});Object.defineProperty(d,"createRoutesFromArray",{enumerable:!0,get:function(){return g.createRoutesFromArray}});Object.defineProperty(d,"createRoutesFromChildren",{enumerable:!0,get:function(){return g.createRoutesFromChildren}});Object.defineProperty(d,"generatePath",{enumerable:!0,get:function(){return g.generatePath}});Object.defineProperty(d,"matchPath",{enumerable:!0,get:function(){return g.matchPath}});Object.defineProperty(d,"matchRoutes",{enumerable:!0,get:function(){return g.matchRoutes}}); Object.defineProperty(d,"resolveLocation",{enumerable:!0,get:function(){return g.resolveLocation}});Object.defineProperty(d,"useBlocker",{enumerable:!0,get:function(){return g.useBlocker}});Object.defineProperty(d,"useHref",{enumerable:!0,get:function(){return g.useHref}});Object.defineProperty(d,"useInRouterContext",{enumerable:!0,get:function(){return g.useInRouterContext}});Object.defineProperty(d,"useLocation",{enumerable:!0,get:function(){return g.useLocation}});Object.defineProperty(d,"useLocationPending", {enumerable:!0,get:function(){return g.useLocationPending}});Object.defineProperty(d,"useMatch",{enumerable:!0,get:function(){return g.useMatch}});Object.defineProperty(d,"useNavigate",{enumerable:!0,get:function(){return g.useNavigate}});Object.defineProperty(d,"useOutlet",{enumerable:!0,get:function(){return g.useOutlet}});Object.defineProperty(d,"useParams",{enumerable:!0,get:function(){return g.useParams}});Object.defineProperty(d,"useResolvedLocation",{enumerable:!0,get:function(){return g.useResolvedLocation}}); Object.defineProperty(d,"useRoutes",{enumerable:!0,get:function(){return g.useRoutes}});d.BrowserRouter=I;d.HashRouter=J;d.Link=w;d.NavLink=L;d.Prompt=K;d.createSearchParams=A;d.usePrompt=O;d.useSearchParams=function(a){V("undefined"!==typeof URLSearchParams,"You cannot use the `useSearchParams` hook in a browser that does not support the URLSearchParams API. If you need to support Internet Explorer 11, we recommend you load a polyfill such as https://github.com/ungap/url-search-params\n\nIf you're unsure how to load polyfills, we recommend you check out https://polyfill.io/v3/ which provides some recommendations about how to load polyfills only for users that need them, instead of for every user."); var b=m.useRef(A(a)),c=g.useLocation();a=m.useMemo(function(){for(var a=A(c.search),d=function(){var c=g.value;a.has(c)||b.current.getAll(c).forEach(function(b){a.append(c,b)})},e=T(b.current.keys()),g;!(g=e()).done;)d();return a},[c.search]);var d=g.useNavigate(),e=m.useCallback(function(a,b){d("?"+A(a),b)},[d]);return[a,e]};Object.defineProperty(d,"__esModule",{value:!0})}); //# sourceMappingURL=react-router-dom.development.js.map