Files

13 lines
16 KiB
JavaScript
Raw Permalink Normal View History

/**
* React Router v6.28.0
*
* Copyright (c) Remix Software Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
import*as e from"react";import{UNSAFE_invariant as t,joinPaths as r,matchPath as a,UNSAFE_decodePath as n,UNSAFE_getResolveToMatches as o,resolveTo as i,parsePath as l,matchRoutes as u,Action as s,UNSAFE_convertRouteMatchToUiMatch as c,stripBasename as d,IDLE_BLOCKER as p,isRouteErrorResponse as h,createMemoryHistory as m,AbortedDeferredError as v,createRouter as f}from"@remix-run/router";export{AbortedDeferredError,Action as NavigationType,createPath,defer,generatePath,isRouteErrorResponse,json,matchPath,matchRoutes,parsePath,redirect,redirectDocument,replace,resolvePath}from"@remix-run/router";const g=e.createContext(null),E=e.createContext(null),y=e.createContext(null),x=e.createContext(null),C=e.createContext(null),b=e.createContext({outlet:null,matches:[],isDataRoute:!1}),R=e.createContext(null);function _(a,{relative:n}={}){S()||t(!1);let{basename:o,navigator:i}=e.useContext(x),{hash:l,pathname:u,search:s}=O(a,{relative:n}),c=u;return"/"!==o&&(c="/"===u?o:r([o,u])),i.createHref({pathname:c,search:s,hash:l})}function S(){return null!=e.useContext(C)}function P(){return S()||t(!1),e.useContext(C).location}function U(){return e.useContext(C).navigationType}function k(r){S()||t(!1);let{pathname:o}=P();return e.useMemo((()=>a(r,n(o))),[o,r])}function D(t){e.useContext(x).static||e.useLayoutEffect(t)}function F(){let{isDataRoute:a}=e.useContext(b);return a?function(){let{router:t}=W(J.UseNavigateStable),r=Y($.UseNavigateStable),a=e.useRef(!1);return D((()=>{a.current=!0})),e.useCallback(((e,n={})=>{a.current&&("number"==typeof e?t.navigate(e):t.navigate(e,{fromRouteId:r,...n}))}),[t,r])}():function(){S()||t(!1);let a=e.useContext(g),{basename:n,future:l,navigator:u}=e.useContext(x),{matches:s}=e.useContext(b),{pathname:c}=P(),d=JSON.stringify(o(s,l.v7_relativeSplatPath)),p=e.useRef(!1);return D((()=>{p.current=!0})),e.useCallback(((e,t={})=>{if(!p.current)return;if("number"==typeof e)return void u.go(e);let o=i(e,JSON.parse(d),c,"path"===t.relative);null==a&&"/"!==n&&(o.pathname="/"===o.pathname?n:r([n,o.pathname])),(t.replace?u.replace:u.push)(o,t.state,t)}),[n,u,d,c,a])}()}const N=e.createContext(null);function B(){return e.useContext(N)}function L(t){let r=e.useContext(b).outlet;return r?e.createElement(N.Provider,{value:t},r):r}function A(){let{matches:t}=e.useContext(b),r=t[t.length-1];return r?r.params:{}}function O(t,{relative:r}={}){let{future:a}=e.useContext(x),{matches:n}=e.useContext(b),{pathname:l}=P(),u=JSON.stringify(o(n,a.v7_relativeSplatPath));return e.useMemo((()=>i(t,JSON.parse(u),l,"path"===r)),[t,u,l,r])}function j(e,t){return T(e,t)}function T(a,n,o,i){S()||t(!1);let{navigator:c}=e.useContext(x),{matches:d}=e.useContext(b),p=d[d.length-1],h=p?p.params:{};!p||p.pathname;let m=p?p.pathnameBase:"/";p&&p.route;let v,f=P();if(n){let e="string"==typeof n?l(n):n;"/"===m||e.pathname?.startsWith(m)||t(!1),v=e}else v=f;let g=v.pathname||"/",E=g;if("/"!==m){let e=m.replace(/^\//,"").split("/");E="/"+g.replace(/^\//,"").split("/").slice(e.length).join("/")}let y=u(a,{pathname:E}),R=z(y&&y.map((e=>Object.assign({},e,{params:Object.assign({},h,e.params),pathname:r([m,c.encodeLocation?c.encodeLocation(e.pathname).pathname:e.pathname]),pathnameBase:"/"===e.pathnameBase?m:r([m,c.encodeLocation?c.encodeLocation(e.pathnameBase).pathname:e.pathnameBase])}))),d,o,i);return n&&R?e.createElement(C.Provider,{value:{location:{pathname:"/",search:"",hash:"",state:null,key:"default",...v},navigationType:s.Pop}},R):R}function M(){let t=te(),r=h(t)?`${t.status} ${t.statusText}`:t instanceof Error?t.message:JSON.stringify(t),a=t instanceof Error?t.stack:null,n={padding:"0.5rem",backgroundColor:"rgba(200,200,200, 0.5)"};return e.createElement(e.Fragment,null,e.createElement("h2",null,"Unexpected Application Error!"),e.createElement("h3",{style:{fontStyle:"italic"}},r),a?e.createElement("pre",{style:n},a):null,null)}const I=e.createElement(M,null);class H extends e.Component{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static g
//# sourceMappingURL=react-router.production.min.js.map