react-router 5.1.0 → 5.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/react-router.js +54 -46
- package/cjs/react-router.js.map +1 -1
- package/cjs/react-router.min.js +1 -1
- package/cjs/react-router.min.js.map +1 -1
- package/es/MemoryRouter.js +0 -2
- package/es/Prompt.js +0 -2
- package/es/Redirect.js +0 -2
- package/es/Route.js +0 -2
- package/es/Router.js +0 -2
- package/es/StaticRouter.js +0 -2
- package/es/Switch.js +0 -2
- package/es/generatePath.js +0 -2
- package/es/matchPath.js +0 -2
- package/es/warnAboutDeprecatedESMImport.js +1 -2
- package/es/withRouter.js +0 -2
- package/esm/react-router.js +43 -46
- package/esm/react-router.js.map +1 -1
- package/modules/HistoryContext.js +4 -0
- package/modules/MemoryRouter.js +1 -1
- package/modules/Prompt.js +2 -2
- package/modules/Redirect.js +3 -3
- package/modules/Route.js +3 -3
- package/modules/Router.js +13 -4
- package/modules/RouterContext.js +1 -9
- package/modules/StaticRouter.js +1 -1
- package/modules/Switch.js +2 -2
- package/modules/createNameContext.js +11 -0
- package/modules/hooks.js +10 -8
- package/modules/index.js +13 -13
- package/modules/matchPath.js +1 -1
- package/modules/withRouter.js +2 -1
- package/package.json +6 -12
- package/umd/react-router.js +67 -74
- package/umd/react-router.js.map +1 -1
- package/umd/react-router.min.js +1 -1
- package/umd/react-router.min.js.map +1 -1
- package/warnAboutDeprecatedCJSRequire.js +1 -0
- package/LICENSE +0 -21
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-router.min.js","sources":["../modules/RouterContext.js","../modules/Router.js","../modules/MemoryRouter.js","../modules/Lifecycle.js","../modules/Prompt.js","../modules/generatePath.js","../modules/Redirect.js","../modules/matchPath.js","../modules/Route.js","../modules/StaticRouter.js","../modules/Switch.js","../modules/withRouter.js","../modules/hooks.js"],"sourcesContent":["// TODO: Replace with React.createContext once we can assume React 16+\nimport createContext from \"mini-create-react-context\";\n\nconst createNamedContext = name => {\n const context = createContext();\n context.displayName = name;\n\n return context;\n};\n\nconst context = /*#__PURE__*/ createNamedContext(\"Router\");\nexport default context;\n","import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport warning from \"tiny-warning\";\n\nimport RouterContext from \"./RouterContext\";\n\n/**\n * The public API for putting history on context.\n */\nclass Router extends React.Component {\n static computeRootMatch(pathname) {\n return { path: \"/\", url: \"/\", params: {}, isExact: pathname === \"/\" };\n }\n\n constructor(props) {\n super(props);\n\n this.state = {\n location: props.history.location\n };\n\n // This is a bit of a hack. We have to start listening for location\n // changes here in the constructor in case there are any <Redirect>s\n // on the initial render. If there are, they will replace/push when\n // they mount and since cDM fires in children before parents, we may\n // get a new location before the <Router> is mounted.\n this._isMounted = false;\n this._pendingLocation = null;\n\n if (!props.staticContext) {\n this.unlisten = props.history.listen(location => {\n if (this._isMounted) {\n this.setState({ location });\n } else {\n this._pendingLocation = location;\n }\n });\n }\n }\n\n componentDidMount() {\n this._isMounted = true;\n\n if (this._pendingLocation) {\n this.setState({ location: this._pendingLocation });\n }\n }\n\n componentWillUnmount() {\n if (this.unlisten) this.unlisten();\n }\n\n render() {\n return (\n <RouterContext.Provider\n children={this.props.children || null}\n value={{\n history: this.props.history,\n location: this.state.location,\n match: Router.computeRootMatch(this.state.location.pathname),\n staticContext: this.props.staticContext\n }}\n />\n );\n }\n}\n\nif (__DEV__) {\n Router.propTypes = {\n children: PropTypes.node,\n history: PropTypes.object.isRequired,\n staticContext: PropTypes.object\n };\n\n Router.prototype.componentDidUpdate = function(prevProps) {\n warning(\n prevProps.history === this.props.history,\n \"You cannot change <Router history>\"\n );\n };\n}\n\nexport default Router;\n","import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport { createMemoryHistory as createHistory } from \"history\";\nimport warning from \"tiny-warning\";\n\nimport Router from \"./Router\";\n\n/**\n * The public API for a <Router> that stores location in memory.\n */\nclass MemoryRouter extends React.Component {\n history = createHistory(this.props);\n\n render() {\n return <Router history={this.history} children={this.props.children} />;\n }\n}\n\nif (__DEV__) {\n MemoryRouter.propTypes = {\n initialEntries: PropTypes.array,\n initialIndex: PropTypes.number,\n getUserConfirmation: PropTypes.func,\n keyLength: PropTypes.number,\n children: PropTypes.node\n };\n\n MemoryRouter.prototype.componentDidMount = function() {\n warning(\n !this.props.history,\n \"<MemoryRouter> ignores the history prop. To use a custom history, \" +\n \"use `import { Router }` instead of `import { MemoryRouter as Router }`.\"\n );\n };\n}\n\nexport default MemoryRouter;\n","import React from \"react\";\n\nclass Lifecycle extends React.Component {\n componentDidMount() {\n if (this.props.onMount) this.props.onMount.call(this, this);\n }\n\n componentDidUpdate(prevProps) {\n if (this.props.onUpdate) this.props.onUpdate.call(this, this, prevProps);\n }\n\n componentWillUnmount() {\n if (this.props.onUnmount) this.props.onUnmount.call(this, this);\n }\n\n render() {\n return null;\n }\n}\n\nexport default Lifecycle;\n","import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport invariant from \"tiny-invariant\";\n\nimport Lifecycle from \"./Lifecycle\";\nimport RouterContext from \"./RouterContext\";\n\n/**\n * The public API for prompting the user before navigating away from a screen.\n */\nfunction Prompt({ message, when = true }) {\n return (\n <RouterContext.Consumer>\n {context => {\n invariant(context, \"You should not use <Prompt> outside a <Router>\");\n\n if (!when || context.staticContext) return null;\n\n const method = context.history.block;\n\n return (\n <Lifecycle\n onMount={self => {\n self.release = method(message);\n }}\n onUpdate={(self, prevProps) => {\n if (prevProps.message !== message) {\n self.release();\n self.release = method(message);\n }\n }}\n onUnmount={self => {\n self.release();\n }}\n message={message}\n />\n );\n }}\n </RouterContext.Consumer>\n );\n}\n\nif (__DEV__) {\n const messageType = PropTypes.oneOfType([PropTypes.func, PropTypes.string]);\n\n Prompt.propTypes = {\n when: PropTypes.bool,\n message: messageType.isRequired\n };\n}\n\nexport default Prompt;\n","import pathToRegexp from \"path-to-regexp\";\n\nconst cache = {};\nconst cacheLimit = 10000;\nlet cacheCount = 0;\n\nfunction compilePath(path) {\n if (cache[path]) return cache[path];\n\n const generator = pathToRegexp.compile(path);\n\n if (cacheCount < cacheLimit) {\n cache[path] = generator;\n cacheCount++;\n }\n\n return generator;\n}\n\n/**\n * Public API for generating a URL pathname from a path and parameters.\n */\nfunction generatePath(path = \"/\", params = {}) {\n return path === \"/\" ? path : compilePath(path)(params, { pretty: true });\n}\n\nexport default generatePath;\n","import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport { createLocation, locationsAreEqual } from \"history\";\nimport invariant from \"tiny-invariant\";\n\nimport Lifecycle from \"./Lifecycle\";\nimport RouterContext from \"./RouterContext\";\nimport generatePath from \"./generatePath\";\n\n/**\n * The public API for navigating programmatically with a component.\n */\nfunction Redirect({ computedMatch, to, push = false }) {\n return (\n <RouterContext.Consumer>\n {context => {\n invariant(context, \"You should not use <Redirect> outside a <Router>\");\n\n const { history, staticContext } = context;\n\n const method = push ? history.push : history.replace;\n const location = createLocation(\n computedMatch\n ? typeof to === \"string\"\n ? generatePath(to, computedMatch.params)\n : {\n ...to,\n pathname: generatePath(to.pathname, computedMatch.params)\n }\n : to\n );\n\n // When rendering in a static context,\n // set the new location immediately.\n if (staticContext) {\n method(location);\n return null;\n }\n\n return (\n <Lifecycle\n onMount={() => {\n method(location);\n }}\n onUpdate={(self, prevProps) => {\n const prevLocation = createLocation(prevProps.to);\n if (\n !locationsAreEqual(prevLocation, {\n ...location,\n key: prevLocation.key\n })\n ) {\n method(location);\n }\n }}\n to={to}\n />\n );\n }}\n </RouterContext.Consumer>\n );\n}\n\nif (__DEV__) {\n Redirect.propTypes = {\n push: PropTypes.bool,\n from: PropTypes.string,\n to: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired\n };\n}\n\nexport default Redirect;\n","import pathToRegexp from \"path-to-regexp\";\n\nconst cache = {};\nconst cacheLimit = 10000;\nlet cacheCount = 0;\n\nfunction compilePath(path, options) {\n const cacheKey = `${options.end}${options.strict}${options.sensitive}`;\n const pathCache = cache[cacheKey] || (cache[cacheKey] = {});\n\n if (pathCache[path]) return pathCache[path];\n\n const keys = [];\n const regexp = pathToRegexp(path, keys, options);\n const result = { regexp, keys };\n\n if (cacheCount < cacheLimit) {\n pathCache[path] = result;\n cacheCount++;\n }\n\n return result;\n}\n\n/**\n * Public API for matching a URL pathname to a path.\n */\nfunction matchPath(pathname, options = {}) {\n if (typeof options === \"string\" || Array.isArray(options)) {\n options = { path: options };\n }\n\n const { path, exact = false, strict = false, sensitive = false } = options;\n\n const paths = [].concat(path);\n\n return paths.reduce((matched, path) => {\n if (!path) return null;\n if (matched) return matched;\n\n const { regexp, keys } = compilePath(path, {\n end: exact,\n strict,\n sensitive\n });\n const match = regexp.exec(pathname);\n\n if (!match) return null;\n\n const [url, ...values] = match;\n const isExact = pathname === url;\n\n if (exact && !isExact) return null;\n\n return {\n path, // the path used to match\n url: path === \"/\" && url === \"\" ? \"/\" : url, // the matched portion of the URL\n isExact, // whether or not we matched exactly\n params: keys.reduce((memo, key, index) => {\n memo[key.name] = values[index];\n return memo;\n }, {})\n };\n }, null);\n}\n\nexport default matchPath;\n","import React from \"react\";\nimport { isValidElementType } from \"react-is\";\nimport PropTypes from \"prop-types\";\nimport invariant from \"tiny-invariant\";\nimport warning from \"tiny-warning\";\n\nimport RouterContext from \"./RouterContext\";\nimport matchPath from \"./matchPath\";\n\nfunction isEmptyChildren(children) {\n return React.Children.count(children) === 0;\n}\n\nfunction evalChildrenDev(children, props, path) {\n const value = children(props);\n\n warning(\n value !== undefined,\n \"You returned `undefined` from the `children` function of \" +\n `<Route${path ? ` path=\"${path}\"` : \"\"}>, but you ` +\n \"should have returned a React element or `null`\"\n );\n\n return value || null;\n}\n\n/**\n * The public API for matching a single path and rendering.\n */\nclass Route extends React.Component {\n render() {\n return (\n <RouterContext.Consumer>\n {context => {\n invariant(context, \"You should not use <Route> outside a <Router>\");\n\n const location = this.props.location || context.location;\n const match = this.props.computedMatch\n ? this.props.computedMatch // <Switch> already computed the match for us\n : this.props.path\n ? matchPath(location.pathname, this.props)\n : context.match;\n\n const props = { ...context, location, match };\n\n let { children, component, render } = this.props;\n\n // Preact uses an empty array as children by\n // default, so use null if that's the case.\n if (Array.isArray(children) && children.length === 0) {\n children = null;\n }\n\n return (\n <RouterContext.Provider value={props}>\n {props.match\n ? children\n ? typeof children === \"function\"\n ? __DEV__\n ? evalChildrenDev(children, props, this.props.path)\n : children(props)\n : children\n : component\n ? React.createElement(component, props)\n : render\n ? render(props)\n : null\n : typeof children === \"function\"\n ? __DEV__\n ? evalChildrenDev(children, props, this.props.path)\n : children(props)\n : null}\n </RouterContext.Provider>\n );\n }}\n </RouterContext.Consumer>\n );\n }\n}\n\nif (__DEV__) {\n Route.propTypes = {\n children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),\n component: (props, propName) => {\n if (props[propName] && !isValidElementType(props[propName])) {\n return new Error(\n `Invalid prop 'component' supplied to 'Route': the prop is not a valid React component`\n );\n }\n },\n exact: PropTypes.bool,\n location: PropTypes.object,\n path: PropTypes.oneOfType([\n PropTypes.string,\n PropTypes.arrayOf(PropTypes.string)\n ]),\n render: PropTypes.func,\n sensitive: PropTypes.bool,\n strict: PropTypes.bool\n };\n\n Route.prototype.componentDidMount = function() {\n warning(\n !(\n this.props.children &&\n !isEmptyChildren(this.props.children) &&\n this.props.component\n ),\n \"You should not use <Route component> and <Route children> in the same route; <Route component> will be ignored\"\n );\n\n warning(\n !(\n this.props.children &&\n !isEmptyChildren(this.props.children) &&\n this.props.render\n ),\n \"You should not use <Route render> and <Route children> in the same route; <Route render> will be ignored\"\n );\n\n warning(\n !(this.props.component && this.props.render),\n \"You should not use <Route component> and <Route render> in the same route; <Route render> will be ignored\"\n );\n };\n\n Route.prototype.componentDidUpdate = function(prevProps) {\n warning(\n !(this.props.location && !prevProps.location),\n '<Route> elements should not change from uncontrolled to controlled (or vice versa). You initially used no \"location\" prop and then provided one on a subsequent render.'\n );\n\n warning(\n !(!this.props.location && prevProps.location),\n '<Route> elements should not change from controlled to uncontrolled (or vice versa). You provided a \"location\" prop initially but omitted it on a subsequent render.'\n );\n };\n}\n\nexport default Route;\n","import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport { createLocation, createPath } from \"history\";\nimport invariant from \"tiny-invariant\";\nimport warning from \"tiny-warning\";\n\nimport Router from \"./Router\";\n\nfunction addLeadingSlash(path) {\n return path.charAt(0) === \"/\" ? path : \"/\" + path;\n}\n\nfunction addBasename(basename, location) {\n if (!basename) return location;\n\n return {\n ...location,\n pathname: addLeadingSlash(basename) + location.pathname\n };\n}\n\nfunction stripBasename(basename, location) {\n if (!basename) return location;\n\n const base = addLeadingSlash(basename);\n\n if (location.pathname.indexOf(base) !== 0) return location;\n\n return {\n ...location,\n pathname: location.pathname.substr(base.length)\n };\n}\n\nfunction createURL(location) {\n return typeof location === \"string\" ? location : createPath(location);\n}\n\nfunction staticHandler(methodName) {\n return () => {\n invariant(false, \"You cannot %s with <StaticRouter>\", methodName);\n };\n}\n\nfunction noop() {}\n\n/**\n * The public top-level API for a \"static\" <Router>, so-called because it\n * can't actually change the current location. Instead, it just records\n * location changes in a context object. Useful mainly in testing and\n * server-rendering scenarios.\n */\nclass StaticRouter extends React.Component {\n navigateTo(location, action) {\n const { basename = \"\", context = {} } = this.props;\n context.action = action;\n context.location = addBasename(basename, createLocation(location));\n context.url = createURL(context.location);\n }\n\n handlePush = location => this.navigateTo(location, \"PUSH\");\n handleReplace = location => this.navigateTo(location, \"REPLACE\");\n handleListen = () => noop;\n handleBlock = () => noop;\n\n render() {\n const { basename = \"\", context = {}, location = \"/\", ...rest } = this.props;\n\n const history = {\n createHref: path => addLeadingSlash(basename + createURL(path)),\n action: \"POP\",\n location: stripBasename(basename, createLocation(location)),\n push: this.handlePush,\n replace: this.handleReplace,\n go: staticHandler(\"go\"),\n goBack: staticHandler(\"goBack\"),\n goForward: staticHandler(\"goForward\"),\n listen: this.handleListen,\n block: this.handleBlock\n };\n\n return <Router {...rest} history={history} staticContext={context} />;\n }\n}\n\nif (__DEV__) {\n StaticRouter.propTypes = {\n basename: PropTypes.string,\n context: PropTypes.object,\n location: PropTypes.oneOfType([PropTypes.string, PropTypes.object])\n };\n\n StaticRouter.prototype.componentDidMount = function() {\n warning(\n !this.props.history,\n \"<StaticRouter> ignores the history prop. To use a custom history, \" +\n \"use `import { Router }` instead of `import { StaticRouter as Router }`.\"\n );\n };\n}\n\nexport default StaticRouter;\n","import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport invariant from \"tiny-invariant\";\nimport warning from \"tiny-warning\";\n\nimport RouterContext from \"./RouterContext\";\nimport matchPath from \"./matchPath\";\n\n/**\n * The public API for rendering the first <Route> that matches.\n */\nclass Switch extends React.Component {\n render() {\n return (\n <RouterContext.Consumer>\n {context => {\n invariant(context, \"You should not use <Switch> outside a <Router>\");\n\n const location = this.props.location || context.location;\n\n let element, match;\n\n // We use React.Children.forEach instead of React.Children.toArray().find()\n // here because toArray adds keys to all child elements and we do not want\n // to trigger an unmount/remount for two <Route>s that render the same\n // component at different URLs.\n React.Children.forEach(this.props.children, child => {\n if (match == null && React.isValidElement(child)) {\n element = child;\n\n const path = child.props.path || child.props.from;\n\n match = path\n ? matchPath(location.pathname, { ...child.props, path })\n : context.match;\n }\n });\n\n return match\n ? React.cloneElement(element, { location, computedMatch: match })\n : null;\n }}\n </RouterContext.Consumer>\n );\n }\n}\n\nif (__DEV__) {\n Switch.propTypes = {\n children: PropTypes.node,\n location: PropTypes.object\n };\n\n Switch.prototype.componentDidUpdate = function(prevProps) {\n warning(\n !(this.props.location && !prevProps.location),\n '<Switch> elements should not change from uncontrolled to controlled (or vice versa). You initially used no \"location\" prop and then provided one on a subsequent render.'\n );\n\n warning(\n !(!this.props.location && prevProps.location),\n '<Switch> elements should not change from controlled to uncontrolled (or vice versa). You provided a \"location\" prop initially but omitted it on a subsequent render.'\n );\n };\n}\n\nexport default Switch;\n","import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport RouterContext from \"./RouterContext\";\nimport hoistStatics from \"hoist-non-react-statics\";\nimport invariant from \"tiny-invariant\";\n\n/**\n * A public higher-order component to access the imperative API\n */\nfunction withRouter(Component) {\n const displayName = `withRouter(${Component.displayName || Component.name})`;\n const C = props => {\n const { wrappedComponentRef, ...remainingProps } = props;\n\n return (\n <RouterContext.Consumer>\n {context => {\n invariant(\n context,\n `You should not use <${displayName} /> outside a <Router>`\n );\n return (\n <Component\n {...remainingProps}\n {...context}\n ref={wrappedComponentRef}\n />\n );\n }}\n </RouterContext.Consumer>\n );\n };\n\n C.displayName = displayName;\n C.WrappedComponent = Component;\n\n if (__DEV__) {\n C.propTypes = {\n wrappedComponentRef: PropTypes.oneOfType([\n PropTypes.string,\n PropTypes.func,\n PropTypes.object\n ])\n };\n }\n\n return hoistStatics(C, Component);\n}\n\nexport default withRouter;\n","import React from \"react\";\nimport invariant from \"tiny-invariant\";\n\nimport Context from \"./RouterContext.js\";\nimport matchPath from \"./matchPath.js\";\n\nconst useContext = React.useContext;\n\nexport function useHistory() {\n if (__DEV__) {\n invariant(\n typeof useContext === \"function\",\n \"You must use React >= 16.8 in order to use useHistory()\"\n );\n }\n\n return useContext(Context).history;\n}\n\nexport function useLocation() {\n if (__DEV__) {\n invariant(\n typeof useContext === \"function\",\n \"You must use React >= 16.8 in order to use useLocation()\"\n );\n }\n\n return useContext(Context).location;\n}\n\nexport function useParams() {\n if (__DEV__) {\n invariant(\n typeof useContext === \"function\",\n \"You must use React >= 16.8 in order to use useParams()\"\n );\n }\n\n return useContext(Context).match.params;\n}\n\nexport function useRouteMatch(path) {\n if (__DEV__) {\n invariant(\n typeof useContext === \"function\",\n \"You must use React >= 16.8 in order to use useMatch()\"\n );\n }\n\n return path\n ? matchPath(useLocation().pathname, path)\n : useContext(Context).match;\n}\n"],"names":["createNamedContext","name","context","createContext","displayName","Router","props","state","location","history","_isMounted","_pendingLocation","staticContext","unlisten","listen","_this","setState","computeRootMatch","pathname","path","url","params","isExact","componentDidMount","this","componentWillUnmount","render","React","RouterContext","Provider","children","value","match","Component","MemoryRouter","createHistory","Lifecycle","onMount","call","componentDidUpdate","prevProps","onUpdate","onUnmount","Prompt","message","when","Consumer","invariant","method","block","self","release","cache","cacheLimit","cacheCount","compilePath","generator","pathToRegexp","compile","generatePath","pretty","Redirect","computedMatch","to","push","replace","createLocation","prevLocation","locationsAreEqual","key","options","cacheKey","end","strict","sensitive","pathCache","keys","result","regexp","matchPath","Array","isArray","exact","concat","reduce","matched","exec","values","memo","index","Route","component","length","createElement","addLeadingSlash","charAt","addBasename","basename","stripBasename","base","indexOf","substr","createURL","createPath","staticHandler","methodName","noop","StaticRouter","handlePush","navigateTo","handleReplace","handleListen","handleBlock","action","rest","createHref","go","goBack","goForward","Switch","element","Children","forEach","child","isValidElement","from","cloneElement","withRouter","C","wrappedComponentRef","remainingProps","ref","WrappedComponent","hoistStatics","useContext","useHistory","Context","useLocation","useParams","useRouteMatch"],"mappings":"0gCAGA,IAAMA,mBAAqB,SAAAC,OACnBC,EAAUC,uBAChBD,EAAQE,YAAcH,EAEfC,GAGHA,QAAwBF,mBAAmB,UCD3CK,8BAKQC,8BACJA,UAEDC,MAAQ,CACXC,SAAUF,EAAMG,QAAQD,YAQrBE,YAAa,IACbC,iBAAmB,KAEnBL,EAAMM,kBACJC,SAAWP,EAAMG,QAAQK,OAAO,SAAAN,GAC/BO,EAAKL,aACFM,SAAS,CAAER,SAAAA,MAEXG,iBAAmBH,6BAxBzBS,iBAAP,SAAwBC,SACf,CAAEC,KAAM,IAAKC,IAAK,IAAKC,OAAQ,GAAIC,QAAsB,MAAbJ,+BA6BrDK,kBAAA,gBACOb,YAAa,EAEdc,KAAKb,uBACFK,SAAS,CAAER,SAAUgB,KAAKb,sBAInCc,qBAAA,WACMD,KAAKX,UAAUW,KAAKX,cAG1Ba,OAAA,kBAEIC,oBAACC,QAAcC,UACbC,SAAUN,KAAKlB,MAAMwB,UAAY,KACjCC,MAAO,CACLtB,QAASe,KAAKlB,MAAMG,QACpBD,SAAUgB,KAAKjB,M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AASC,QAAQ3G,EAAKT,MAAMwB,SAAU,SAAA6F,MAC7B,MAAT3F,GAAiBL,MAAMiG,eAAeD,GAAQ,KAG1CxG,GAFNqG,EAAUG,GAESrH,MAAMa,MAAQwG,EAAMrH,MAAMuH,KAE7C7F,EAAQb,EACJ4D,UAAUvE,EAASU,qBAAeyG,EAAMrH,OAAOa,KAAAA,KAC/CjB,EAAQ8B,SAITA,EACHL,MAAMmG,aAAaN,EAAS,CAAEhH,SAAAA,EAAUsD,cAAe9B,IACvD,WA7BOL,MAAMM,WCF3B,SAAS8F,WAAW9F,GAER,SAAJ+F,EAAI1H,OACA2H,EAA2C3H,EAA3C2H,oBAAwBC,gCAAmB5H,kCAGjDqB,oBAACC,QAAckB,cACZ,SAAA5C,UAEGA,GADF6C,cAKEpB,oBAACM,cACKiG,EACAhI,GACJiI,IAAKF,WAfX7H,iBAA4B6B,EAAU7B,aAAe6B,EAAUhC,iBAuBrE+H,EAAE5H,YAAcA,EAChB4H,EAAEI,iBAAmBnG,EAYdoG,aAAaL,EAAG/F,GCxCzB,IAAMqG,WAAa3G,MAAM2G,WAEzB,SAAgBC,oBAQPD,WAAWE,SAAS/H,QAG7B,SAAgBgI,qBAQPH,WAAWE,SAAShI,SAG7B,SAAgBkI,mBAQPJ,WAAWE,SAASxG,MAAMX,OAG5B,SAASsH,cAAcxH,UAQrBA,EACH4D,UAAU0D,cAAcvH,SAAUC,GAClCmH,WAAWE,SAASxG"}
|
|
1
|
+
{"version":3,"file":"react-router.min.js","sources":["../modules/createNameContext.js","../modules/HistoryContext.js","../modules/RouterContext.js","../modules/Router.js","../modules/MemoryRouter.js","../modules/Lifecycle.js","../modules/Prompt.js","../modules/generatePath.js","../modules/Redirect.js","../modules/matchPath.js","../modules/Route.js","../modules/StaticRouter.js","../modules/Switch.js","../modules/withRouter.js","../modules/hooks.js"],"sourcesContent":["// TODO: Replace with React.createContext once we can assume React 16+\nimport createContext from \"mini-create-react-context\";\n\nconst createNamedContext = name => {\n const context = createContext();\n context.displayName = name;\n\n return context;\n};\n\nexport default createNamedContext;\n","import createNamedContext from \"./createNameContext\";\n\nconst historyContext = /*#__PURE__*/ createNamedContext(\"Router-History\");\nexport default historyContext;\n","import createNamedContext from \"./createNameContext\";\n\nconst context = /*#__PURE__*/ createNamedContext(\"Router\");\nexport default context;\n","import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport warning from \"tiny-warning\";\n\nimport HistoryContext from \"./HistoryContext.js\";\nimport RouterContext from \"./RouterContext.js\";\n\n/**\n * The public API for putting history on context.\n */\nclass Router extends React.Component {\n static computeRootMatch(pathname) {\n return { path: \"/\", url: \"/\", params: {}, isExact: pathname === \"/\" };\n }\n\n constructor(props) {\n super(props);\n\n this.state = {\n location: props.history.location\n };\n\n // This is a bit of a hack. We have to start listening for location\n // changes here in the constructor in case there are any <Redirect>s\n // on the initial render. If there are, they will replace/push when\n // they mount and since cDM fires in children before parents, we may\n // get a new location before the <Router> is mounted.\n this._isMounted = false;\n this._pendingLocation = null;\n\n if (!props.staticContext) {\n this.unlisten = props.history.listen(location => {\n if (this._isMounted) {\n this.setState({ location });\n } else {\n this._pendingLocation = location;\n }\n });\n }\n }\n\n componentDidMount() {\n this._isMounted = true;\n\n if (this._pendingLocation) {\n this.setState({ location: this._pendingLocation });\n }\n }\n\n componentWillUnmount() {\n if (this.unlisten) {\n this.unlisten();\n this._isMounted = false;\n this._pendingLocation = null;\n }\n }\n\n render() {\n return (\n <RouterContext.Provider\n value={{\n history: this.props.history,\n location: this.state.location,\n match: Router.computeRootMatch(this.state.location.pathname),\n staticContext: this.props.staticContext\n }}\n >\n <HistoryContext.Provider\n children={this.props.children || null}\n value={this.props.history}\n />\n </RouterContext.Provider>\n );\n }\n}\n\nif (__DEV__) {\n Router.propTypes = {\n children: PropTypes.node,\n history: PropTypes.object.isRequired,\n staticContext: PropTypes.object\n };\n\n Router.prototype.componentDidUpdate = function(prevProps) {\n warning(\n prevProps.history === this.props.history,\n \"You cannot change <Router history>\"\n );\n };\n}\n\nexport default Router;\n","import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport { createMemoryHistory as createHistory } from \"history\";\nimport warning from \"tiny-warning\";\n\nimport Router from \"./Router.js\";\n\n/**\n * The public API for a <Router> that stores location in memory.\n */\nclass MemoryRouter extends React.Component {\n history = createHistory(this.props);\n\n render() {\n return <Router history={this.history} children={this.props.children} />;\n }\n}\n\nif (__DEV__) {\n MemoryRouter.propTypes = {\n initialEntries: PropTypes.array,\n initialIndex: PropTypes.number,\n getUserConfirmation: PropTypes.func,\n keyLength: PropTypes.number,\n children: PropTypes.node\n };\n\n MemoryRouter.prototype.componentDidMount = function() {\n warning(\n !this.props.history,\n \"<MemoryRouter> ignores the history prop. To use a custom history, \" +\n \"use `import { Router }` instead of `import { MemoryRouter as Router }`.\"\n );\n };\n}\n\nexport default MemoryRouter;\n","import React from \"react\";\n\nclass Lifecycle extends React.Component {\n componentDidMount() {\n if (this.props.onMount) this.props.onMount.call(this, this);\n }\n\n componentDidUpdate(prevProps) {\n if (this.props.onUpdate) this.props.onUpdate.call(this, this, prevProps);\n }\n\n componentWillUnmount() {\n if (this.props.onUnmount) this.props.onUnmount.call(this, this);\n }\n\n render() {\n return null;\n }\n}\n\nexport default Lifecycle;\n","import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport invariant from \"tiny-invariant\";\n\nimport Lifecycle from \"./Lifecycle.js\";\nimport RouterContext from \"./RouterContext.js\";\n\n/**\n * The public API for prompting the user before navigating away from a screen.\n */\nfunction Prompt({ message, when = true }) {\n return (\n <RouterContext.Consumer>\n {context => {\n invariant(context, \"You should not use <Prompt> outside a <Router>\");\n\n if (!when || context.staticContext) return null;\n\n const method = context.history.block;\n\n return (\n <Lifecycle\n onMount={self => {\n self.release = method(message);\n }}\n onUpdate={(self, prevProps) => {\n if (prevProps.message !== message) {\n self.release();\n self.release = method(message);\n }\n }}\n onUnmount={self => {\n self.release();\n }}\n message={message}\n />\n );\n }}\n </RouterContext.Consumer>\n );\n}\n\nif (__DEV__) {\n const messageType = PropTypes.oneOfType([PropTypes.func, PropTypes.string]);\n\n Prompt.propTypes = {\n when: PropTypes.bool,\n message: messageType.isRequired\n };\n}\n\nexport default Prompt;\n","import pathToRegexp from \"path-to-regexp\";\n\nconst cache = {};\nconst cacheLimit = 10000;\nlet cacheCount = 0;\n\nfunction compilePath(path) {\n if (cache[path]) return cache[path];\n\n const generator = pathToRegexp.compile(path);\n\n if (cacheCount < cacheLimit) {\n cache[path] = generator;\n cacheCount++;\n }\n\n return generator;\n}\n\n/**\n * Public API for generating a URL pathname from a path and parameters.\n */\nfunction generatePath(path = \"/\", params = {}) {\n return path === \"/\" ? path : compilePath(path)(params, { pretty: true });\n}\n\nexport default generatePath;\n","import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport { createLocation, locationsAreEqual } from \"history\";\nimport invariant from \"tiny-invariant\";\n\nimport Lifecycle from \"./Lifecycle.js\";\nimport RouterContext from \"./RouterContext.js\";\nimport generatePath from \"./generatePath.js\";\n\n/**\n * The public API for navigating programmatically with a component.\n */\nfunction Redirect({ computedMatch, to, push = false }) {\n return (\n <RouterContext.Consumer>\n {context => {\n invariant(context, \"You should not use <Redirect> outside a <Router>\");\n\n const { history, staticContext } = context;\n\n const method = push ? history.push : history.replace;\n const location = createLocation(\n computedMatch\n ? typeof to === \"string\"\n ? generatePath(to, computedMatch.params)\n : {\n ...to,\n pathname: generatePath(to.pathname, computedMatch.params)\n }\n : to\n );\n\n // When rendering in a static context,\n // set the new location immediately.\n if (staticContext) {\n method(location);\n return null;\n }\n\n return (\n <Lifecycle\n onMount={() => {\n method(location);\n }}\n onUpdate={(self, prevProps) => {\n const prevLocation = createLocation(prevProps.to);\n if (\n !locationsAreEqual(prevLocation, {\n ...location,\n key: prevLocation.key\n })\n ) {\n method(location);\n }\n }}\n to={to}\n />\n );\n }}\n </RouterContext.Consumer>\n );\n}\n\nif (__DEV__) {\n Redirect.propTypes = {\n push: PropTypes.bool,\n from: PropTypes.string,\n to: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired\n };\n}\n\nexport default Redirect;\n","import pathToRegexp from \"path-to-regexp\";\n\nconst cache = {};\nconst cacheLimit = 10000;\nlet cacheCount = 0;\n\nfunction compilePath(path, options) {\n const cacheKey = `${options.end}${options.strict}${options.sensitive}`;\n const pathCache = cache[cacheKey] || (cache[cacheKey] = {});\n\n if (pathCache[path]) return pathCache[path];\n\n const keys = [];\n const regexp = pathToRegexp(path, keys, options);\n const result = { regexp, keys };\n\n if (cacheCount < cacheLimit) {\n pathCache[path] = result;\n cacheCount++;\n }\n\n return result;\n}\n\n/**\n * Public API for matching a URL pathname to a path.\n */\nfunction matchPath(pathname, options = {}) {\n if (typeof options === \"string\" || Array.isArray(options)) {\n options = { path: options };\n }\n\n const { path, exact = false, strict = false, sensitive = false } = options;\n\n const paths = [].concat(path);\n\n return paths.reduce((matched, path) => {\n if (!path && path !== \"\") return null;\n if (matched) return matched;\n\n const { regexp, keys } = compilePath(path, {\n end: exact,\n strict,\n sensitive\n });\n const match = regexp.exec(pathname);\n\n if (!match) return null;\n\n const [url, ...values] = match;\n const isExact = pathname === url;\n\n if (exact && !isExact) return null;\n\n return {\n path, // the path used to match\n url: path === \"/\" && url === \"\" ? \"/\" : url, // the matched portion of the URL\n isExact, // whether or not we matched exactly\n params: keys.reduce((memo, key, index) => {\n memo[key.name] = values[index];\n return memo;\n }, {})\n };\n }, null);\n}\n\nexport default matchPath;\n","import React from \"react\";\nimport { isValidElementType } from \"react-is\";\nimport PropTypes from \"prop-types\";\nimport invariant from \"tiny-invariant\";\nimport warning from \"tiny-warning\";\n\nimport RouterContext from \"./RouterContext.js\";\nimport matchPath from \"./matchPath.js\";\n\nfunction isEmptyChildren(children) {\n return React.Children.count(children) === 0;\n}\n\nfunction evalChildrenDev(children, props, path) {\n const value = children(props);\n\n warning(\n value !== undefined,\n \"You returned `undefined` from the `children` function of \" +\n `<Route${path ? ` path=\"${path}\"` : \"\"}>, but you ` +\n \"should have returned a React element or `null`\"\n );\n\n return value || null;\n}\n\n/**\n * The public API for matching a single path and rendering.\n */\nclass Route extends React.Component {\n render() {\n return (\n <RouterContext.Consumer>\n {context => {\n invariant(context, \"You should not use <Route> outside a <Router>\");\n\n const location = this.props.location || context.location;\n const match = this.props.computedMatch\n ? this.props.computedMatch // <Switch> already computed the match for us\n : this.props.path\n ? matchPath(location.pathname, this.props)\n : context.match;\n\n const props = { ...context, location, match };\n\n let { children, component, render } = this.props;\n\n // Preact uses an empty array as children by\n // default, so use null if that's the case.\n if (Array.isArray(children) && isEmptyChildren(children)) {\n children = null;\n }\n\n return (\n <RouterContext.Provider value={props}>\n {props.match\n ? children\n ? typeof children === \"function\"\n ? __DEV__\n ? evalChildrenDev(children, props, this.props.path)\n : children(props)\n : children\n : component\n ? React.createElement(component, props)\n : render\n ? render(props)\n : null\n : typeof children === \"function\"\n ? __DEV__\n ? evalChildrenDev(children, props, this.props.path)\n : children(props)\n : null}\n </RouterContext.Provider>\n );\n }}\n </RouterContext.Consumer>\n );\n }\n}\n\nif (__DEV__) {\n Route.propTypes = {\n children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),\n component: (props, propName) => {\n if (props[propName] && !isValidElementType(props[propName])) {\n return new Error(\n `Invalid prop 'component' supplied to 'Route': the prop is not a valid React component`\n );\n }\n },\n exact: PropTypes.bool,\n location: PropTypes.object,\n path: PropTypes.oneOfType([\n PropTypes.string,\n PropTypes.arrayOf(PropTypes.string)\n ]),\n render: PropTypes.func,\n sensitive: PropTypes.bool,\n strict: PropTypes.bool\n };\n\n Route.prototype.componentDidMount = function() {\n warning(\n !(\n this.props.children &&\n !isEmptyChildren(this.props.children) &&\n this.props.component\n ),\n \"You should not use <Route component> and <Route children> in the same route; <Route component> will be ignored\"\n );\n\n warning(\n !(\n this.props.children &&\n !isEmptyChildren(this.props.children) &&\n this.props.render\n ),\n \"You should not use <Route render> and <Route children> in the same route; <Route render> will be ignored\"\n );\n\n warning(\n !(this.props.component && this.props.render),\n \"You should not use <Route component> and <Route render> in the same route; <Route render> will be ignored\"\n );\n };\n\n Route.prototype.componentDidUpdate = function(prevProps) {\n warning(\n !(this.props.location && !prevProps.location),\n '<Route> elements should not change from uncontrolled to controlled (or vice versa). You initially used no \"location\" prop and then provided one on a subsequent render.'\n );\n\n warning(\n !(!this.props.location && prevProps.location),\n '<Route> elements should not change from controlled to uncontrolled (or vice versa). You provided a \"location\" prop initially but omitted it on a subsequent render.'\n );\n };\n}\n\nexport default Route;\n","import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport { createLocation, createPath } from \"history\";\nimport invariant from \"tiny-invariant\";\nimport warning from \"tiny-warning\";\n\nimport Router from \"./Router.js\";\n\nfunction addLeadingSlash(path) {\n return path.charAt(0) === \"/\" ? path : \"/\" + path;\n}\n\nfunction addBasename(basename, location) {\n if (!basename) return location;\n\n return {\n ...location,\n pathname: addLeadingSlash(basename) + location.pathname\n };\n}\n\nfunction stripBasename(basename, location) {\n if (!basename) return location;\n\n const base = addLeadingSlash(basename);\n\n if (location.pathname.indexOf(base) !== 0) return location;\n\n return {\n ...location,\n pathname: location.pathname.substr(base.length)\n };\n}\n\nfunction createURL(location) {\n return typeof location === \"string\" ? location : createPath(location);\n}\n\nfunction staticHandler(methodName) {\n return () => {\n invariant(false, \"You cannot %s with <StaticRouter>\", methodName);\n };\n}\n\nfunction noop() {}\n\n/**\n * The public top-level API for a \"static\" <Router>, so-called because it\n * can't actually change the current location. Instead, it just records\n * location changes in a context object. Useful mainly in testing and\n * server-rendering scenarios.\n */\nclass StaticRouter extends React.Component {\n navigateTo(location, action) {\n const { basename = \"\", context = {} } = this.props;\n context.action = action;\n context.location = addBasename(basename, createLocation(location));\n context.url = createURL(context.location);\n }\n\n handlePush = location => this.navigateTo(location, \"PUSH\");\n handleReplace = location => this.navigateTo(location, \"REPLACE\");\n handleListen = () => noop;\n handleBlock = () => noop;\n\n render() {\n const { basename = \"\", context = {}, location = \"/\", ...rest } = this.props;\n\n const history = {\n createHref: path => addLeadingSlash(basename + createURL(path)),\n action: \"POP\",\n location: stripBasename(basename, createLocation(location)),\n push: this.handlePush,\n replace: this.handleReplace,\n go: staticHandler(\"go\"),\n goBack: staticHandler(\"goBack\"),\n goForward: staticHandler(\"goForward\"),\n listen: this.handleListen,\n block: this.handleBlock\n };\n\n return <Router {...rest} history={history} staticContext={context} />;\n }\n}\n\nif (__DEV__) {\n StaticRouter.propTypes = {\n basename: PropTypes.string,\n context: PropTypes.object,\n location: PropTypes.oneOfType([PropTypes.string, PropTypes.object])\n };\n\n StaticRouter.prototype.componentDidMount = function() {\n warning(\n !this.props.history,\n \"<StaticRouter> ignores the history prop. To use a custom history, \" +\n \"use `import { Router }` instead of `import { StaticRouter as Router }`.\"\n );\n };\n}\n\nexport default StaticRouter;\n","import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport invariant from \"tiny-invariant\";\nimport warning from \"tiny-warning\";\n\nimport RouterContext from \"./RouterContext.js\";\nimport matchPath from \"./matchPath.js\";\n\n/**\n * The public API for rendering the first <Route> that matches.\n */\nclass Switch extends React.Component {\n render() {\n return (\n <RouterContext.Consumer>\n {context => {\n invariant(context, \"You should not use <Switch> outside a <Router>\");\n\n const location = this.props.location || context.location;\n\n let element, match;\n\n // We use React.Children.forEach instead of React.Children.toArray().find()\n // here because toArray adds keys to all child elements and we do not want\n // to trigger an unmount/remount for two <Route>s that render the same\n // component at different URLs.\n React.Children.forEach(this.props.children, child => {\n if (match == null && React.isValidElement(child)) {\n element = child;\n\n const path = child.props.path || child.props.from;\n\n match = path\n ? matchPath(location.pathname, { ...child.props, path })\n : context.match;\n }\n });\n\n return match\n ? React.cloneElement(element, { location, computedMatch: match })\n : null;\n }}\n </RouterContext.Consumer>\n );\n }\n}\n\nif (__DEV__) {\n Switch.propTypes = {\n children: PropTypes.node,\n location: PropTypes.object\n };\n\n Switch.prototype.componentDidUpdate = function(prevProps) {\n warning(\n !(this.props.location && !prevProps.location),\n '<Switch> elements should not change from uncontrolled to controlled (or vice versa). You initially used no \"location\" prop and then provided one on a subsequent render.'\n );\n\n warning(\n !(!this.props.location && prevProps.location),\n '<Switch> elements should not change from controlled to uncontrolled (or vice versa). You provided a \"location\" prop initially but omitted it on a subsequent render.'\n );\n };\n}\n\nexport default Switch;\n","import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport hoistStatics from \"hoist-non-react-statics\";\nimport invariant from \"tiny-invariant\";\n\nimport RouterContext from \"./RouterContext.js\";\n\n/**\n * A public higher-order component to access the imperative API\n */\nfunction withRouter(Component) {\n const displayName = `withRouter(${Component.displayName || Component.name})`;\n const C = props => {\n const { wrappedComponentRef, ...remainingProps } = props;\n\n return (\n <RouterContext.Consumer>\n {context => {\n invariant(\n context,\n `You should not use <${displayName} /> outside a <Router>`\n );\n return (\n <Component\n {...remainingProps}\n {...context}\n ref={wrappedComponentRef}\n />\n );\n }}\n </RouterContext.Consumer>\n );\n };\n\n C.displayName = displayName;\n C.WrappedComponent = Component;\n\n if (__DEV__) {\n C.propTypes = {\n wrappedComponentRef: PropTypes.oneOfType([\n PropTypes.string,\n PropTypes.func,\n PropTypes.object\n ])\n };\n }\n\n return hoistStatics(C, Component);\n}\n\nexport default withRouter;\n","import React from \"react\";\nimport invariant from \"tiny-invariant\";\n\nimport RouterContext from \"./RouterContext.js\";\nimport HistoryContext from \"./HistoryContext.js\";\nimport matchPath from \"./matchPath.js\";\n\nconst useContext = React.useContext;\n\nexport function useHistory() {\n if (__DEV__) {\n invariant(\n typeof useContext === \"function\",\n \"You must use React >= 16.8 in order to use useHistory()\"\n );\n }\n\n return useContext(HistoryContext);\n}\n\nexport function useLocation() {\n if (__DEV__) {\n invariant(\n typeof useContext === \"function\",\n \"You must use React >= 16.8 in order to use useLocation()\"\n );\n }\n\n return useContext(RouterContext).location;\n}\n\nexport function useParams() {\n if (__DEV__) {\n invariant(\n typeof useContext === \"function\",\n \"You must use React >= 16.8 in order to use useParams()\"\n );\n }\n\n const match = useContext(RouterContext).match;\n return match ? match.params : {};\n}\n\nexport function useRouteMatch(path) {\n if (__DEV__) {\n invariant(\n typeof useContext === \"function\",\n \"You must use React >= 16.8 in order to use useRouteMatch()\"\n );\n }\n\n const location = useLocation();\n const match = useContext(RouterContext).match;\n return path ? matchPath(location.pathname, path) : match;\n}\n"],"names":["createNamedContext","name","context","createContext","displayName","historyContext","Router","props","state","location","history","_isMounted","_pendingLocation","staticContext","unlisten","listen","_this","setState","computeRootMatch","pathname","path","url","params","isExact","componentDidMount","this","componentWillUnmount","render","React","RouterContext","Provider","value","match","HistoryContext","children","Component","MemoryRouter","createHistory","Lifecycle","onMount","call","componentDidUpdate","prevProps","onUpdate","onUnmount","Prompt","message","when","Consumer","invariant","method","block","self","release","cache","cacheLimit","cacheCount","compilePath","generator","pathToRegexp","compile","generatePath","pretty","Redirect","computedMatch","to","push","replace","createLocation","prevLocation","locationsAreEqual","key","options","cacheKey","end","strict","sensitive","pathCache","keys","result","regexp","matchPath","Array","isArray","exact","concat","reduce","matched","exec","values","memo","index","isEmptyChildren","Children","count","Route","component","createElement","addLeadingSlash","charAt","addBasename","basename","stripBasename","base","indexOf","substr","length","createURL","createPath","staticHandler","methodName","noop","StaticRouter","handlePush","navigateTo","handleReplace","handleListen","handleBlock","action","rest","createHref","go","goBack","goForward","Switch","element","forEach","child","isValidElement","from","cloneElement","withRouter","C","wrappedComponentRef","remainingProps","ref","WrappedComponent","hoistStatics","useContext","useHistory","useLocation","useParams","useRouteMatch"],"mappings":"uoCAGA,IAAMA,mBAAqB,SAAAC,OACnBC,EAAUC,uBAChBD,EAAQE,YAAcH,EAEfC,GCLHG,eAA+BL,mBAAmB,kBCAlDE,QAAwBF,mBAAmB,UCQ3CM,8BAKQC,8BACJA,UAEDC,MAAQ,CACXC,SAAUF,EAAMG,QAAQD,YAQrBE,YAAa,IACbC,iBAAmB,KAEnBL,EAAMM,kBACJC,SAAWP,EAAMG,QAAQK,OAAO,SAAAN,GAC/BO,EAAKL,aACFM,SAAS,CAAER,SAAA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oBAQPD,WAAWzG,gBAGpB,SAAgB2G,qBAQPF,WAAW7G,SAAepB,SAGnC,SAAgBoI,gBAQR7G,EAAQ0G,WAAW7G,SAAeG,aACjCA,EAAQA,EAAMV,OAAS,GAGzB,SAASwH,cAAc1H,OAQtBX,EAAWmI,cACX5G,EAAQ0G,WAAW7G,SAAeG,aACjCZ,EAAO6D,UAAUxE,EAASU,SAAUC,GAAQY"}
|
package/es/MemoryRouter.js
CHANGED
package/es/Prompt.js
CHANGED
package/es/Redirect.js
CHANGED
package/es/Route.js
CHANGED
package/es/Router.js
CHANGED
package/es/StaticRouter.js
CHANGED
package/es/Switch.js
CHANGED
package/es/generatePath.js
CHANGED
package/es/matchPath.js
CHANGED
package/es/withRouter.js
CHANGED
package/esm/react-router.js
CHANGED
|
@@ -19,17 +19,15 @@ var createNamedContext = function createNamedContext(name) {
|
|
|
19
19
|
return context;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
createNamedContext("Router");
|
|
22
|
+
var historyContext = /*#__PURE__*/createNamedContext("Router-History");
|
|
23
|
+
|
|
24
|
+
var context = /*#__PURE__*/createNamedContext("Router");
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* The public API for putting history on context.
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
-
var Router =
|
|
31
|
-
/*#__PURE__*/
|
|
32
|
-
function (_React$Component) {
|
|
30
|
+
var Router = /*#__PURE__*/function (_React$Component) {
|
|
33
31
|
_inheritsLoose(Router, _React$Component);
|
|
34
32
|
|
|
35
33
|
Router.computeRootMatch = function computeRootMatch(pathname) {
|
|
@@ -84,19 +82,25 @@ function (_React$Component) {
|
|
|
84
82
|
};
|
|
85
83
|
|
|
86
84
|
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
87
|
-
if (this.unlisten)
|
|
85
|
+
if (this.unlisten) {
|
|
86
|
+
this.unlisten();
|
|
87
|
+
this._isMounted = false;
|
|
88
|
+
this._pendingLocation = null;
|
|
89
|
+
}
|
|
88
90
|
};
|
|
89
91
|
|
|
90
92
|
_proto.render = function render() {
|
|
91
|
-
return React.createElement(context.Provider, {
|
|
92
|
-
children: this.props.children || null,
|
|
93
|
+
return /*#__PURE__*/React.createElement(context.Provider, {
|
|
93
94
|
value: {
|
|
94
95
|
history: this.props.history,
|
|
95
96
|
location: this.state.location,
|
|
96
97
|
match: Router.computeRootMatch(this.state.location.pathname),
|
|
97
98
|
staticContext: this.props.staticContext
|
|
98
99
|
}
|
|
99
|
-
}
|
|
100
|
+
}, /*#__PURE__*/React.createElement(historyContext.Provider, {
|
|
101
|
+
children: this.props.children || null,
|
|
102
|
+
value: this.props.history
|
|
103
|
+
}));
|
|
100
104
|
};
|
|
101
105
|
|
|
102
106
|
return Router;
|
|
@@ -118,9 +122,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
118
122
|
* The public API for a <Router> that stores location in memory.
|
|
119
123
|
*/
|
|
120
124
|
|
|
121
|
-
var MemoryRouter =
|
|
122
|
-
/*#__PURE__*/
|
|
123
|
-
function (_React$Component) {
|
|
125
|
+
var MemoryRouter = /*#__PURE__*/function (_React$Component) {
|
|
124
126
|
_inheritsLoose(MemoryRouter, _React$Component);
|
|
125
127
|
|
|
126
128
|
function MemoryRouter() {
|
|
@@ -138,7 +140,7 @@ function (_React$Component) {
|
|
|
138
140
|
var _proto = MemoryRouter.prototype;
|
|
139
141
|
|
|
140
142
|
_proto.render = function render() {
|
|
141
|
-
return React.createElement(Router, {
|
|
143
|
+
return /*#__PURE__*/React.createElement(Router, {
|
|
142
144
|
history: this.history,
|
|
143
145
|
children: this.props.children
|
|
144
146
|
});
|
|
@@ -161,9 +163,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
161
163
|
};
|
|
162
164
|
}
|
|
163
165
|
|
|
164
|
-
var Lifecycle =
|
|
165
|
-
/*#__PURE__*/
|
|
166
|
-
function (_React$Component) {
|
|
166
|
+
var Lifecycle = /*#__PURE__*/function (_React$Component) {
|
|
167
167
|
_inheritsLoose(Lifecycle, _React$Component);
|
|
168
168
|
|
|
169
169
|
function Lifecycle() {
|
|
@@ -199,11 +199,11 @@ function Prompt(_ref) {
|
|
|
199
199
|
var message = _ref.message,
|
|
200
200
|
_ref$when = _ref.when,
|
|
201
201
|
when = _ref$when === void 0 ? true : _ref$when;
|
|
202
|
-
return React.createElement(context.Consumer, null, function (context) {
|
|
202
|
+
return /*#__PURE__*/React.createElement(context.Consumer, null, function (context) {
|
|
203
203
|
!context ? process.env.NODE_ENV !== "production" ? invariant(false, "You should not use <Prompt> outside a <Router>") : invariant(false) : void 0;
|
|
204
204
|
if (!when || context.staticContext) return null;
|
|
205
205
|
var method = context.history.block;
|
|
206
|
-
return React.createElement(Lifecycle, {
|
|
206
|
+
return /*#__PURE__*/React.createElement(Lifecycle, {
|
|
207
207
|
onMount: function onMount(self) {
|
|
208
208
|
self.release = method(message);
|
|
209
209
|
},
|
|
@@ -272,7 +272,7 @@ function Redirect(_ref) {
|
|
|
272
272
|
to = _ref.to,
|
|
273
273
|
_ref$push = _ref.push,
|
|
274
274
|
push = _ref$push === void 0 ? false : _ref$push;
|
|
275
|
-
return React.createElement(context.Consumer, null, function (context) {
|
|
275
|
+
return /*#__PURE__*/React.createElement(context.Consumer, null, function (context) {
|
|
276
276
|
!context ? process.env.NODE_ENV !== "production" ? invariant(false, "You should not use <Redirect> outside a <Router>") : invariant(false) : void 0;
|
|
277
277
|
var history = context.history,
|
|
278
278
|
staticContext = context.staticContext;
|
|
@@ -287,7 +287,7 @@ function Redirect(_ref) {
|
|
|
287
287
|
return null;
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
return React.createElement(Lifecycle, {
|
|
290
|
+
return /*#__PURE__*/React.createElement(Lifecycle, {
|
|
291
291
|
onMount: function onMount() {
|
|
292
292
|
method(location);
|
|
293
293
|
},
|
|
@@ -361,7 +361,7 @@ function matchPath(pathname, options) {
|
|
|
361
361
|
sensitive = _options$sensitive === void 0 ? false : _options$sensitive;
|
|
362
362
|
var paths = [].concat(path);
|
|
363
363
|
return paths.reduce(function (matched, path) {
|
|
364
|
-
if (!path) return null;
|
|
364
|
+
if (!path && path !== "") return null;
|
|
365
365
|
if (matched) return matched;
|
|
366
366
|
|
|
367
367
|
var _compilePath = compilePath$1(path, {
|
|
@@ -407,9 +407,7 @@ function evalChildrenDev(children, props, path) {
|
|
|
407
407
|
*/
|
|
408
408
|
|
|
409
409
|
|
|
410
|
-
var Route =
|
|
411
|
-
/*#__PURE__*/
|
|
412
|
-
function (_React$Component) {
|
|
410
|
+
var Route = /*#__PURE__*/function (_React$Component) {
|
|
413
411
|
_inheritsLoose(Route, _React$Component);
|
|
414
412
|
|
|
415
413
|
function Route() {
|
|
@@ -421,7 +419,7 @@ function (_React$Component) {
|
|
|
421
419
|
_proto.render = function render() {
|
|
422
420
|
var _this = this;
|
|
423
421
|
|
|
424
|
-
return React.createElement(context.Consumer, null, function (context$1) {
|
|
422
|
+
return /*#__PURE__*/React.createElement(context.Consumer, null, function (context$1) {
|
|
425
423
|
!context$1 ? process.env.NODE_ENV !== "production" ? invariant(false, "You should not use <Route> outside a <Router>") : invariant(false) : void 0;
|
|
426
424
|
var location = _this.props.location || context$1.location;
|
|
427
425
|
var match = _this.props.computedMatch ? _this.props.computedMatch // <Switch> already computed the match for us
|
|
@@ -438,13 +436,13 @@ function (_React$Component) {
|
|
|
438
436
|
render = _this$props.render; // Preact uses an empty array as children by
|
|
439
437
|
// default, so use null if that's the case.
|
|
440
438
|
|
|
441
|
-
if (Array.isArray(children) && children
|
|
439
|
+
if (Array.isArray(children) && isEmptyChildren(children)) {
|
|
442
440
|
children = null;
|
|
443
441
|
}
|
|
444
442
|
|
|
445
|
-
return React.createElement(context.Provider, {
|
|
443
|
+
return /*#__PURE__*/React.createElement(context.Provider, {
|
|
446
444
|
value: props
|
|
447
|
-
}, props.match ? children ? typeof children === "function" ? process.env.NODE_ENV !== "production" ? evalChildrenDev(children, props, _this.props.path) : children(props) : children : component ? React.createElement(component, props) : render ? render(props) : null : typeof children === "function" ? process.env.NODE_ENV !== "production" ? evalChildrenDev(children, props, _this.props.path) : children(props) : null);
|
|
445
|
+
}, props.match ? children ? typeof children === "function" ? process.env.NODE_ENV !== "production" ? evalChildrenDev(children, props, _this.props.path) : children(props) : children : component ? /*#__PURE__*/React.createElement(component, props) : render ? render(props) : null : typeof children === "function" ? process.env.NODE_ENV !== "production" ? evalChildrenDev(children, props, _this.props.path) : children(props) : null);
|
|
448
446
|
});
|
|
449
447
|
};
|
|
450
448
|
|
|
@@ -518,9 +516,7 @@ function noop() {}
|
|
|
518
516
|
*/
|
|
519
517
|
|
|
520
518
|
|
|
521
|
-
var StaticRouter =
|
|
522
|
-
/*#__PURE__*/
|
|
523
|
-
function (_React$Component) {
|
|
519
|
+
var StaticRouter = /*#__PURE__*/function (_React$Component) {
|
|
524
520
|
_inheritsLoose(StaticRouter, _React$Component);
|
|
525
521
|
|
|
526
522
|
function StaticRouter() {
|
|
@@ -588,7 +584,7 @@ function (_React$Component) {
|
|
|
588
584
|
listen: this.handleListen,
|
|
589
585
|
block: this.handleBlock
|
|
590
586
|
};
|
|
591
|
-
return React.createElement(Router, _extends({}, rest, {
|
|
587
|
+
return /*#__PURE__*/React.createElement(Router, _extends({}, rest, {
|
|
592
588
|
history: history,
|
|
593
589
|
staticContext: context
|
|
594
590
|
}));
|
|
@@ -613,9 +609,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
613
609
|
* The public API for rendering the first <Route> that matches.
|
|
614
610
|
*/
|
|
615
611
|
|
|
616
|
-
var Switch =
|
|
617
|
-
/*#__PURE__*/
|
|
618
|
-
function (_React$Component) {
|
|
612
|
+
var Switch = /*#__PURE__*/function (_React$Component) {
|
|
619
613
|
_inheritsLoose(Switch, _React$Component);
|
|
620
614
|
|
|
621
615
|
function Switch() {
|
|
@@ -627,7 +621,7 @@ function (_React$Component) {
|
|
|
627
621
|
_proto.render = function render() {
|
|
628
622
|
var _this = this;
|
|
629
623
|
|
|
630
|
-
return React.createElement(context.Consumer, null, function (context) {
|
|
624
|
+
return /*#__PURE__*/React.createElement(context.Consumer, null, function (context) {
|
|
631
625
|
!context ? process.env.NODE_ENV !== "production" ? invariant(false, "You should not use <Switch> outside a <Router>") : invariant(false) : void 0;
|
|
632
626
|
var location = _this.props.location || context.location;
|
|
633
627
|
var element, match; // We use React.Children.forEach instead of React.Children.toArray().find()
|
|
@@ -636,7 +630,7 @@ function (_React$Component) {
|
|
|
636
630
|
// component at different URLs.
|
|
637
631
|
|
|
638
632
|
React.Children.forEach(_this.props.children, function (child) {
|
|
639
|
-
if (match == null && React.isValidElement(child)) {
|
|
633
|
+
if (match == null && /*#__PURE__*/React.isValidElement(child)) {
|
|
640
634
|
element = child;
|
|
641
635
|
var path = child.props.path || child.props.from;
|
|
642
636
|
match = path ? matchPath(location.pathname, _extends({}, child.props, {
|
|
@@ -644,7 +638,7 @@ function (_React$Component) {
|
|
|
644
638
|
})) : context.match;
|
|
645
639
|
}
|
|
646
640
|
});
|
|
647
|
-
return match ? React.cloneElement(element, {
|
|
641
|
+
return match ? /*#__PURE__*/React.cloneElement(element, {
|
|
648
642
|
location: location,
|
|
649
643
|
computedMatch: match
|
|
650
644
|
}) : null;
|
|
@@ -677,9 +671,9 @@ function withRouter(Component) {
|
|
|
677
671
|
var wrappedComponentRef = props.wrappedComponentRef,
|
|
678
672
|
remainingProps = _objectWithoutPropertiesLoose(props, ["wrappedComponentRef"]);
|
|
679
673
|
|
|
680
|
-
return React.createElement(context.Consumer, null, function (context) {
|
|
674
|
+
return /*#__PURE__*/React.createElement(context.Consumer, null, function (context) {
|
|
681
675
|
!context ? process.env.NODE_ENV !== "production" ? invariant(false, "You should not use <" + displayName + " /> outside a <Router>") : invariant(false) : void 0;
|
|
682
|
-
return React.createElement(Component, _extends({}, remainingProps, context, {
|
|
676
|
+
return /*#__PURE__*/React.createElement(Component, _extends({}, remainingProps, context, {
|
|
683
677
|
ref: wrappedComponentRef
|
|
684
678
|
}));
|
|
685
679
|
});
|
|
@@ -703,7 +697,7 @@ function useHistory() {
|
|
|
703
697
|
!(typeof useContext === "function") ? process.env.NODE_ENV !== "production" ? invariant(false, "You must use React >= 16.8 in order to use useHistory()") : invariant(false) : void 0;
|
|
704
698
|
}
|
|
705
699
|
|
|
706
|
-
return useContext(
|
|
700
|
+
return useContext(historyContext);
|
|
707
701
|
}
|
|
708
702
|
function useLocation() {
|
|
709
703
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -717,14 +711,17 @@ function useParams() {
|
|
|
717
711
|
!(typeof useContext === "function") ? process.env.NODE_ENV !== "production" ? invariant(false, "You must use React >= 16.8 in order to use useParams()") : invariant(false) : void 0;
|
|
718
712
|
}
|
|
719
713
|
|
|
720
|
-
|
|
714
|
+
var match = useContext(context).match;
|
|
715
|
+
return match ? match.params : {};
|
|
721
716
|
}
|
|
722
717
|
function useRouteMatch(path) {
|
|
723
718
|
if (process.env.NODE_ENV !== "production") {
|
|
724
|
-
!(typeof useContext === "function") ? process.env.NODE_ENV !== "production" ? invariant(false, "You must use React >= 16.8 in order to use
|
|
719
|
+
!(typeof useContext === "function") ? process.env.NODE_ENV !== "production" ? invariant(false, "You must use React >= 16.8 in order to use useRouteMatch()") : invariant(false) : void 0;
|
|
725
720
|
}
|
|
726
721
|
|
|
727
|
-
|
|
722
|
+
var location = useLocation();
|
|
723
|
+
var match = useContext(context).match;
|
|
724
|
+
return path ? matchPath(location.pathname, path) : match;
|
|
728
725
|
}
|
|
729
726
|
|
|
730
727
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -749,5 +746,5 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
749
746
|
}
|
|
750
747
|
}
|
|
751
748
|
|
|
752
|
-
export { MemoryRouter, Prompt, Redirect, Route, Router, StaticRouter, Switch, context as __RouterContext, generatePath, matchPath, useHistory, useLocation, useParams, useRouteMatch, withRouter };
|
|
749
|
+
export { MemoryRouter, Prompt, Redirect, Route, Router, StaticRouter, Switch, historyContext as __HistoryContext, context as __RouterContext, generatePath, matchPath, useHistory, useLocation, useParams, useRouteMatch, withRouter };
|
|
753
750
|
//# sourceMappingURL=react-router.js.map
|