{"ast":null,"code":"\"use strict\";\n\nexports.__esModule = true;\nexports.addBasePath = addBasePath;\nexports.delBasePath = delBasePath;\nexports.default = void 0;\n\nvar _url2 = require(\"url\");\n\nvar _mitt = _interopRequireDefault(require(\"../mitt\"));\n\nvar _utils = require(\"../utils\");\n\nvar _isDynamic = require(\"./utils/is-dynamic\");\n\nvar _routeMatcher = require(\"./utils/route-matcher\");\n\nvar _routeRegex = require(\"./utils/route-regex\");\n\nfunction _interopRequireDefault(obj) {\n  return obj && obj.__esModule ? obj : {\n    default: obj\n  };\n}\n/* global __NEXT_DATA__ */\n// tslint:disable:no-console\n\n\nconst basePath = process.env.__NEXT_ROUTER_BASEPATH || '';\n\nfunction addBasePath(path) {\n  return path.indexOf(basePath) !== 0 ? basePath + path : path;\n}\n\nfunction delBasePath(path) {\n  return path.indexOf(basePath) === 0 ? path.substr(basePath.length) || '/' : path;\n}\n\nfunction toRoute(path) {\n  return path.replace(/\\/$/, '') || '/';\n}\n\nconst prepareRoute = path => toRoute(!path || path === '/' ? '/index' : path);\n\nfunction fetchNextData(pathname, query, isServerRender, cb) {\n  let attempts = isServerRender ? 3 : 1;\n\n  function getResponse() {\n    return fetch((0, _utils.formatWithValidation)({\n      pathname: addBasePath( // @ts-ignore __NEXT_DATA__\n      `/_next/data/${__NEXT_DATA__.buildId}${delBasePath(pathname)}.json`),\n      query\n    }), {\n      // Cookies are required to be present for Next.js' SSG \"Preview Mode\".\n      // Cookies may also be required for `getServerSideProps`.\n      //\n      // > `fetch` won’t send cookies, unless you set the credentials init\n      // > option.\n      // https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch\n      //\n      // > For maximum browser compatibility when it comes to sending &\n      // > receiving cookies, always supply the `credentials: 'same-origin'`\n      // > option instead of relying on the default.\n      // https://github.com/github/fetch#caveats\n      credentials: 'same-origin'\n    }).then(res => {\n      if (!res.ok) {\n        if (--attempts > 0 && res.status >= 500) {\n          return getResponse();\n        }\n\n        throw new Error(`Failed to load static props`);\n      }\n\n      return res.json();\n    });\n  }\n\n  return getResponse().then(data => {\n    return cb ? cb(data) : data;\n  }).catch(err => {\n    // We should only trigger a server-side transition if this was caused\n    // on a client-side transition. Otherwise, we'd get into an infinite\n    // loop.\n    if (!isServerRender) {\n      ;\n      err.code = 'PAGE_LOAD_ERROR';\n    }\n\n    throw err;\n  });\n}\n\nclass Router {\n  /**\n  * Map of all components loaded in `Router`\n  */\n  // Static Data Cache\n  constructor(_pathname, _query, _as2, {\n    initialProps,\n    pageLoader,\n    App,\n    wrapApp,\n    Component,\n    err,\n    subscription,\n    isFallback\n  }) {\n    this.route = void 0;\n    this.pathname = void 0;\n    this.query = void 0;\n    this.asPath = void 0;\n    this.basePath = void 0;\n    this.components = void 0;\n    this.sdc = {};\n    this.sub = void 0;\n    this.clc = void 0;\n    this.pageLoader = void 0;\n    this._bps = void 0;\n    this.events = void 0;\n    this._wrapApp = void 0;\n    this.isSsr = void 0;\n    this.isFallback = void 0;\n\n    this.onPopState = e => {\n      if (!e.state) {\n        // We get state as undefined for two reasons.\n        //  1. With older safari (< 8) and older chrome (< 34)\n        //  2. When the URL changed with #\n        //\n        // In the both cases, we don't need to proceed and change the route.\n        // (as it's already changed)\n        // But we can simply replace the state with the new changes.\n        // Actually, for (1) we don't need to nothing. But it's hard to detect that event.\n        // So, doing the following for (1) does no harm.\n        const {\n          pathname,\n          query\n        } = this;\n        this.changeState('replaceState', (0, _utils.formatWithValidation)({\n          pathname,\n          query\n        }), (0, _utils.getURL)());\n        return;\n      } // Make sure we don't re-render on initial load,\n      // can be caused by navigating back from an external site\n\n\n      if (e.state && this.isSsr && e.state.as === this.asPath && (0, _url2.parse)(e.state.url).pathname === this.pathname) {\n        return;\n      } // If the downstream application returns falsy, return.\n      // They will then be responsible for handling the event.\n\n\n      if (this._bps && !this._bps(e.state)) {\n        return;\n      }\n\n      const {\n        url,\n        as,\n        options\n      } = e.state;\n\n      if (true) {\n        if (typeof url === 'undefined' || typeof as === 'undefined') {\n          console.warn('`popstate` event triggered but `event.state` did not have `url` or `as` https://err.sh/vercel/next.js/popstate-state-empty');\n        }\n      }\n\n      this.replace(url, as, options);\n    };\n\n    this._getStaticData = asPath => {\n      const pathname = prepareRoute((0, _url2.parse)(asPath).pathname);\n      return false && this.sdc[pathname] ? Promise.resolve(this.sdc[pathname]) : fetchNextData(pathname, null, this.isSsr, data => this.sdc[pathname] = data);\n    };\n\n    this._getServerData = asPath => {\n      let {\n        pathname,\n        query\n      } = (0, _url2.parse)(asPath, true);\n      pathname = prepareRoute(pathname);\n      return fetchNextData(pathname, query, this.isSsr);\n    }; // represents the current component key\n\n\n    this.route = toRoute(_pathname); // set up the component cache (by route keys)\n\n    this.components = {}; // We should not keep the cache, if there's an error\n    // Otherwise, this cause issues when when going back and\n    // come again to the errored page.\n\n    if (_pathname !== '/_error') {\n      this.components[this.route] = {\n        Component,\n        props: initialProps,\n        err,\n        __N_SSG: initialProps && initialProps.__N_SSG,\n        __N_SSP: initialProps && initialProps.__N_SSP\n      };\n    }\n\n    this.components['/_app'] = {\n      Component: App\n    }; // Backwards compat for Router.router.events\n    // TODO: Should be remove the following major version as it was never documented\n\n    this.events = Router.events;\n    this.pageLoader = pageLoader;\n    this.pathname = _pathname;\n    this.query = _query; // if auto prerendered and dynamic route wait to update asPath\n    // until after mount to prevent hydration mismatch\n\n    this.asPath = // @ts-ignore this is temporarily global (attached to window)\n    (0, _isDynamic.isDynamicRoute)(_pathname) && __NEXT_DATA__.autoExport ? _pathname : _as2;\n    this.basePath = basePath;\n    this.sub = subscription;\n    this.clc = null;\n    this._wrapApp = wrapApp; // make sure to ignore extra popState in safari on navigating\n    // back from external site\n\n    this.isSsr = true;\n    this.isFallback = isFallback;\n\n    if (false) {\n      // make sure \"as\" doesn't start with double slashes or else it can\n      // throw an error as it's considered invalid\n      if (_as2.substr(0, 2) !== '//') {\n        // in order for `e.state` to work on the `onpopstate` event\n        // we have to register the initial route upon initialization\n        this.changeState('replaceState', (0, _utils.formatWithValidation)({\n          pathname: _pathname,\n          query: _query\n        }), _as2);\n      }\n\n      window.addEventListener('popstate', this.onPopState);\n    }\n  } // @deprecated backwards compatibility even though it's a private method.\n\n\n  static _rewriteUrlForNextExport(url) {\n    if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {\n      const rewriteUrlForNextExport = require('./rewrite-url-for-export').rewriteUrlForNextExport;\n\n      return rewriteUrlForNextExport(url);\n    } else {\n      return url;\n    }\n  }\n\n  update(route, mod) {\n    const Component = mod.default || mod;\n    const data = this.components[route];\n\n    if (!data) {\n      throw new Error(`Cannot update unavailable route: ${route}`);\n    }\n\n    const newData = Object.assign({}, data, {\n      Component,\n      __N_SSG: mod.__N_SSG,\n      __N_SSP: mod.__N_SSP\n    });\n    this.components[route] = newData; // pages/_app.js updated\n\n    if (route === '/_app') {\n      this.notify(this.components[this.route]);\n      return;\n    }\n\n    if (route === this.route) {\n      this.notify(newData);\n    }\n  }\n\n  reload() {\n    window.location.reload();\n  }\n  /**\n  * Go back in history\n  */\n\n\n  back() {\n    window.history.back();\n  }\n  /**\n  * Performs a `pushState` with arguments\n  * @param url of the route\n  * @param as masks `url` for the browser\n  * @param options object you can define `shallow` and other options\n  */\n\n\n  push(url, as = url, options = {}) {\n    return this.change('pushState', url, as, options);\n  }\n  /**\n  * Performs a `replaceState` with arguments\n  * @param url of the route\n  * @param as masks `url` for the browser\n  * @param options object you can define `shallow` and other options\n  */\n\n\n  replace(url, as = url, options = {}) {\n    return this.change('replaceState', url, as, options);\n  }\n\n  change(method, _url, _as, options) {\n    return new Promise((resolve, reject) => {\n      if (!options._h) {\n        this.isSsr = false;\n      } // marking route changes as a navigation start entry\n\n\n      if (_utils.ST) {\n        performance.mark('routeChange');\n      } // If url and as provided as an object representation,\n      // we'll format them into the string version here.\n\n\n      let url = typeof _url === 'object' ? (0, _utils.formatWithValidation)(_url) : _url;\n      let as = typeof _as === 'object' ? (0, _utils.formatWithValidation)(_as) : _as;\n      url = addBasePath(url);\n      as = addBasePath(as); // Add the ending slash to the paths. So, we can serve the\n      // \"<page>/index.html\" directly for the SSR page.\n\n      if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {\n        const rewriteUrlForNextExport = require('./rewrite-url-for-export').rewriteUrlForNextExport; // @ts-ignore this is temporarily global (attached to window)\n\n\n        if (__NEXT_DATA__.nextExport) {\n          as = rewriteUrlForNextExport(as);\n        }\n      }\n\n      this.abortComponentLoad(as); // If the url change is only related to a hash change\n      // We should not proceed. We should only change the state.\n      // WARNING: `_h` is an internal option for handing Next.js client-side\n      // hydration. Your app should _never_ use this property. It may change at\n      // any time without notice.\n\n      if (!options._h && this.onlyAHashChange(as)) {\n        this.asPath = as;\n        Router.events.emit('hashChangeStart', as);\n        this.changeState(method, url, as, options);\n        this.scrollToHash(as);\n        Router.events.emit('hashChangeComplete', as);\n        return resolve(true);\n      }\n\n      const {\n        pathname,\n        query,\n        protocol\n      } = (0, _url2.parse)(url, true);\n\n      if (!pathname || protocol) {\n        if (true) {\n          throw new Error(`Invalid href passed to router: ${url} https://err.sh/vercel/next.js/invalid-href-passed`);\n        }\n\n        return resolve(false);\n      } // If asked to change the current URL we should reload the current page\n      // (not location.reload() but reload getInitialProps and other Next.js stuffs)\n      // We also need to set the method = replaceState always\n      // as this should not go into the history (That's how browsers work)\n      // We should compare the new asPath to the current asPath, not the url\n\n\n      if (!this.urlIsNew(as)) {\n        method = 'replaceState';\n      }\n\n      const route = toRoute(pathname);\n      const {\n        shallow = false\n      } = options;\n\n      if ((0, _isDynamic.isDynamicRoute)(route)) {\n        const {\n          pathname: asPathname\n        } = (0, _url2.parse)(as);\n        const routeRegex = (0, _routeRegex.getRouteRegex)(route);\n        const routeMatch = (0, _routeMatcher.getRouteMatcher)(routeRegex)(asPathname);\n\n        if (!routeMatch) {\n          const missingParams = Object.keys(routeRegex.groups).filter(param => !query[param]);\n\n          if (missingParams.length > 0) {\n            if (true) {\n              console.warn(`Mismatching \\`as\\` and \\`href\\` failed to manually provide ` + `the params: ${missingParams.join(', ')} in the \\`href\\`'s \\`query\\``);\n            }\n\n            return reject(new Error(`The provided \\`as\\` value (${asPathname}) is incompatible with the \\`href\\` value (${route}). ` + `Read more: https://err.sh/vercel/next.js/incompatible-href-as`));\n          }\n        } else {\n          // Merge params into `query`, overwriting any specified in search\n          Object.assign(query, routeMatch);\n        }\n      }\n\n      Router.events.emit('routeChangeStart', as); // If shallow is true and the route exists in the router cache we reuse the previous result\n\n      this.getRouteInfo(route, pathname, query, as, shallow).then(routeInfo => {\n        const {\n          error\n        } = routeInfo;\n\n        if (error && error.cancelled) {\n          return resolve(false);\n        }\n\n        Router.events.emit('beforeHistoryChange', as);\n        this.changeState(method, url, as, options);\n\n        if (true) {\n          const appComp = this.components['/_app'].Component;\n          window.next.isPrerendered = appComp.getInitialProps === appComp.origGetInitialProps && !routeInfo.Component.getInitialProps;\n        }\n\n        this.set(route, pathname, query, as, routeInfo).then(() => {\n          if (error) {\n            Router.events.emit('routeChangeError', error, as);\n            throw error;\n          }\n\n          Router.events.emit('routeChangeComplete', as);\n          return resolve(true);\n        });\n      }, reject);\n    });\n  }\n\n  changeState(method, url, as, options = {}) {\n    if (true) {\n      if (typeof window.history === 'undefined') {\n        console.error(`Warning: window.history is not available.`);\n        return;\n      }\n\n      if (typeof window.history[method] === 'undefined') {\n        console.error(`Warning: window.history.${method} is not available`);\n        return;\n      }\n    }\n\n    if (method !== 'pushState' || (0, _utils.getURL)() !== as) {\n      window.history[method]({\n        url,\n        as,\n        options\n      }, // Most browsers currently ignores this parameter, although they may use it in the future.\n      // Passing the empty string here should be safe against future changes to the method.\n      // https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState\n      '', as);\n    }\n  }\n\n  getRouteInfo(route, pathname, query, as, shallow = false) {\n    const cachedRouteInfo = this.components[route]; // If there is a shallow route transition possible\n    // If the route is already rendered on the screen.\n\n    if (shallow && cachedRouteInfo && this.route === route) {\n      return Promise.resolve(cachedRouteInfo);\n    }\n\n    const handleError = (err, loadErrorFail) => {\n      return new Promise(resolve => {\n        if (err.code === 'PAGE_LOAD_ERROR' || loadErrorFail) {\n          // If we can't load the page it could be one of following reasons\n          //  1. Page doesn't exists\n          //  2. Page does exist in a different zone\n          //  3. Internal error while loading the page\n          // So, doing a hard reload is the proper way to deal with this.\n          window.location.href = as; // Changing the URL doesn't block executing the current code path.\n          // So, we need to mark it as a cancelled error and stop the routing logic.\n\n          err.cancelled = true; // @ts-ignore TODO: fix the control flow here\n\n          return resolve({\n            error: err\n          });\n        }\n\n        if (err.cancelled) {\n          // @ts-ignore TODO: fix the control flow here\n          return resolve({\n            error: err\n          });\n        }\n\n        resolve(this.fetchComponent('/_error').then(res => {\n          const {\n            page: Component\n          } = res;\n          const routeInfo = {\n            Component,\n            err\n          };\n          return new Promise(resolve => {\n            this.getInitialProps(Component, {\n              err,\n              pathname,\n              query\n            }).then(props => {\n              routeInfo.props = props;\n              routeInfo.error = err;\n              resolve(routeInfo);\n            }, gipErr => {\n              console.error('Error in error page `getInitialProps`: ', gipErr);\n              routeInfo.error = err;\n              routeInfo.props = {};\n              resolve(routeInfo);\n            });\n          });\n        }).catch(err => handleError(err, true)));\n      });\n    };\n\n    return new Promise((resolve, reject) => {\n      if (cachedRouteInfo) {\n        return resolve(cachedRouteInfo);\n      }\n\n      this.fetchComponent(route).then(res => resolve({\n        Component: res.page,\n        __N_SSG: res.mod.__N_SSG,\n        __N_SSP: res.mod.__N_SSP\n      }), reject);\n    }).then(routeInfo => {\n      const {\n        Component,\n        __N_SSG,\n        __N_SSP\n      } = routeInfo;\n\n      if (true) {\n        const {\n          isValidElementType\n        } = require('react-is');\n\n        if (!isValidElementType(Component)) {\n          throw new Error(`The default export is not a React Component in page: \"${pathname}\"`);\n        }\n      }\n\n      return this._getData(() => __N_SSG ? this._getStaticData(as) : __N_SSP ? this._getServerData(as) : this.getInitialProps(Component, // we provide AppTree later so this needs to be `any`\n      {\n        pathname,\n        query,\n        asPath: as\n      })).then(props => {\n        routeInfo.props = props;\n        this.components[route] = routeInfo;\n        return routeInfo;\n      });\n    }).catch(handleError);\n  }\n\n  set(route, pathname, query, as, data) {\n    this.isFallback = false;\n    this.route = route;\n    this.pathname = pathname;\n    this.query = query;\n    this.asPath = as;\n    return this.notify(data);\n  }\n  /**\n  * Callback to execute before replacing router state\n  * @param cb callback to be executed\n  */\n\n\n  beforePopState(cb) {\n    this._bps = cb;\n  }\n\n  onlyAHashChange(as) {\n    if (!this.asPath) return false;\n    const [oldUrlNoHash, oldHash] = this.asPath.split('#');\n    const [newUrlNoHash, newHash] = as.split('#'); // Makes sure we scroll to the provided hash if the url/hash are the same\n\n    if (newHash && oldUrlNoHash === newUrlNoHash && oldHash === newHash) {\n      return true;\n    } // If the urls are change, there's more than a hash change\n\n\n    if (oldUrlNoHash !== newUrlNoHash) {\n      return false;\n    } // If the hash has changed, then it's a hash only change.\n    // This check is necessary to handle both the enter and\n    // leave hash === '' cases. The identity case falls through\n    // and is treated as a next reload.\n\n\n    return oldHash !== newHash;\n  }\n\n  scrollToHash(as) {\n    const [, hash] = as.split('#'); // Scroll to top if the hash is just `#` with no value\n\n    if (hash === '') {\n      window.scrollTo(0, 0);\n      return;\n    } // First we check if the element by id is found\n\n\n    const idEl = document.getElementById(hash);\n\n    if (idEl) {\n      idEl.scrollIntoView();\n      return;\n    } // If there's no element with the id, we check the `name` property\n    // To mirror browsers\n\n\n    const nameEl = document.getElementsByName(hash)[0];\n\n    if (nameEl) {\n      nameEl.scrollIntoView();\n    }\n  }\n\n  urlIsNew(asPath) {\n    return this.asPath !== asPath;\n  }\n  /**\n  * Prefetch page code, you may wait for the data during page rendering.\n  * This feature only works in production!\n  * @param url the href of prefetched page\n  * @param asPath the as path of the prefetched page\n  */\n\n\n  prefetch(url, asPath = url, options = {}) {\n    return new Promise((resolve, reject) => {\n      const {\n        pathname,\n        protocol\n      } = (0, _url2.parse)(url);\n\n      if (!pathname || protocol) {\n        if (true) {\n          throw new Error(`Invalid href passed to router: ${url} https://err.sh/vercel/next.js/invalid-href-passed`);\n        }\n\n        return;\n      } // Prefetch is not supported in development mode because it would trigger on-demand-entries\n\n\n      if (true) {\n        return;\n      }\n\n      const route = delBasePath(toRoute(pathname));\n      Promise.all([this.pageLoader.prefetchData(url, delBasePath(asPath)), this.pageLoader[options.priority ? 'loadPage' : 'prefetch'](route)]).then(() => resolve(), reject);\n    });\n  }\n\n  async fetchComponent(route) {\n    let cancelled = false;\n\n    const cancel = this.clc = () => {\n      cancelled = true;\n    };\n\n    route = delBasePath(route);\n    const componentResult = await this.pageLoader.loadPage(route);\n\n    if (cancelled) {\n      const error = new Error(`Abort fetching component for route: \"${route}\"`);\n      error.cancelled = true;\n      throw error;\n    }\n\n    if (cancel === this.clc) {\n      this.clc = null;\n    }\n\n    return componentResult;\n  }\n\n  _getData(fn) {\n    let cancelled = false;\n\n    const cancel = () => {\n      cancelled = true;\n    };\n\n    this.clc = cancel;\n    return fn().then(data => {\n      if (cancel === this.clc) {\n        this.clc = null;\n      }\n\n      if (cancelled) {\n        const err = new Error('Loading initial props cancelled');\n        err.cancelled = true;\n        throw err;\n      }\n\n      return data;\n    });\n  }\n\n  getInitialProps(Component, ctx) {\n    const {\n      Component: App\n    } = this.components['/_app'];\n\n    const AppTree = this._wrapApp(App);\n\n    ctx.AppTree = AppTree;\n    return (0, _utils.loadGetInitialProps)(App, {\n      AppTree,\n      Component,\n      router: this,\n      ctx\n    });\n  }\n\n  abortComponentLoad(as) {\n    if (this.clc) {\n      const e = new Error('Route Cancelled');\n      e.cancelled = true;\n      Router.events.emit('routeChangeError', e, as);\n      this.clc();\n      this.clc = null;\n    }\n  }\n\n  notify(data) {\n    return this.sub(data, this.components['/_app'].Component);\n  }\n\n}\n\nexports.default = Router;\nRouter.events = (0, _mitt.default)();","map":{"version":3,"sources":["../../../../next-server/lib/router/router.ts"],"names":["basePath","process","path","prepareRoute","toRoute","attempts","isServerRender","pathname","addBasePath","__NEXT_DATA__","buildId","delBasePath","credentials","res","getResponse","data","cb","err","Router","route","query","asPath","components","sdc","sub","clc","pageLoader","_bps","events","_wrapApp","isSsr","isFallback","constructor","props","__N_SSG","initialProps","__N_SSP","Component","as","window","rewriteUrlForNextExport","require","e","console","update","mod","newData","Object","reload","back","push","options","replace","change","ST","performance","url","resolve","method","shallow","routeRegex","routeMatch","missingParams","param","reject","asPathname","routeInfo","error","appComp","changeState","getRouteInfo","cachedRouteInfo","Promise","handleError","page","gipErr","isValidElementType","set","beforePopState","onlyAHashChange","newHash","oldUrlNoHash","oldHash","scrollToHash","hash","idEl","document","nameEl","urlIsNew","prefetch","cancelled","cancel","componentResult","_getData","fn","fetchNextData","getInitialProps","AppTree","ctx","router","abortComponentLoad","notify"],"mappings":";;;;;;;AAIA,IAAA,KAAA,GAAA,OAAA,CAAA,KAAA,CAAA;;AACA,IAAA,KAAA,GAAA,sBAAA,CAAA,OAAA,CAAA,SAAA,CAAA,CAAA;;AACA,IAAA,MAAA,GAAA,OAAA,CAAA,UAAA,CAAA;;AAQA,IAAA,UAAA,GAAA,OAAA,CAAA,oBAAA,CAAA;;AACA,IAAA,aAAA,GAAA,OAAA,CAAA,uBAAA,CAAA;;AACA,IAAA,WAAA,GAAA,OAAA,CAAA,qBAAA,CAAA;;;;;;AAhBA;AAAA;AACA;;;AAiBA,MAAMA,QAAQ,GAAIC,OAAO,CAAPA,GAAAA,CAAD,sBAACA,IAAlB,EAAA;;AAEO,SAAA,WAAA,CAAA,IAAA,EAA2C;AAChD,SAAOC,IAAI,CAAJA,OAAAA,CAAAA,QAAAA,MAAAA,CAAAA,GAA+BF,QAAQ,GAAvCE,IAAAA,GAAP,IAAA;AAGK;;AAAA,SAAA,WAAA,CAAA,IAAA,EAA2C;AAChD,SAAOA,IAAI,CAAJA,OAAAA,CAAAA,QAAAA,MAAAA,CAAAA,GACHA,IAAI,CAAJA,MAAAA,CAAYF,QAAQ,CAApBE,MAAAA,KADGA,GAAAA,GAAP,IAAA;AAKF;;AAAA,SAAA,OAAA,CAAA,IAAA,EAAuC;AACrC,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AAP;AAQFC;;AAAAA,EAAAA,kBAAkB,CAAA,EAAA,EAAmB;AACnC,QAAI,KAAJ,GAAA,EAAc;AACZ,YAAM1D,CAAC,GAAG,IAAA,KAAA,CAAV,iBAAU,CAAV;AACEA,MAAAA,CAAD,CAAA,SAACA,GAAD,IAACA;AACFxB,MAAAA,MAAM,CAANA,MAAAA,CAAAA,IAAAA,CAAAA,kBAAAA,EAAAA,CAAAA,EAAAA,EAAAA;AACA,WAAA,GAAA;AACA,WAAA,GAAA,GAAA,IAAA;AAEH;AAEDmF;;AAAAA,EAAAA,MAAM,CAAA,IAAA,EAAiC;AACrC,WAAO,KAAA,GAAA,CAAA,IAAA,EAAe,KAAA,UAAA,CAAA,OAAA,EAAtB,SAAO,CAAP;AA/sB8C;;AAAA;;;AAA7BnF,M,CAsBZU,MAtBYV,GAsBU,CAAA,GAAA,KAAA,CAAA,OAAA,GAtBVA","sourcesContent":["/* global __NEXT_DATA__ */\n// tslint:disable:no-console\nimport { ParsedUrlQuery } from 'querystring'\nimport { ComponentType } from 'react'\nimport { parse, UrlObject } from 'url'\nimport mitt, { MittEmitter } from '../mitt'\nimport {\n  AppContextType,\n  formatWithValidation,\n  getURL,\n  loadGetInitialProps,\n  NextPageContext,\n  ST,\n} from '../utils'\nimport { isDynamicRoute } from './utils/is-dynamic'\nimport { getRouteMatcher } from './utils/route-matcher'\nimport { getRouteRegex } from './utils/route-regex'\n\nconst basePath = (process.env.__NEXT_ROUTER_BASEPATH as string) || ''\n\nexport function addBasePath(path: string): string {\n  return path.indexOf(basePath) !== 0 ? basePath + path : path\n}\n\nexport function delBasePath(path: string): string {\n  return path.indexOf(basePath) === 0\n    ? path.substr(basePath.length) || '/'\n    : path\n}\n\nfunction toRoute(path: string): string {\n  return path.replace(/\\/$/, '') || '/'\n}\n\nconst prepareRoute = (path: string) =>\n  toRoute(!path || path === '/' ? '/index' : path)\n\ntype Url = UrlObject | string\n\ntype ComponentRes = { page: ComponentType; mod: any }\n\nexport type BaseRouter = {\n  route: string\n  pathname: string\n  query: ParsedUrlQuery\n  asPath: string\n  basePath: string\n}\n\nexport type NextRouter = BaseRouter &\n  Pick<\n    Router,\n    | 'push'\n    | 'replace'\n    | 'reload'\n    | 'back'\n    | 'prefetch'\n    | 'beforePopState'\n    | 'events'\n    | 'isFallback'\n  >\n\nexport type PrefetchOptions = {\n  priority?: boolean\n}\n\ntype RouteInfo = {\n  Component: ComponentType\n  __N_SSG?: boolean\n  __N_SSP?: boolean\n  props?: any\n  err?: Error\n  error?: any\n}\n\ntype Subscription = (data: RouteInfo, App?: ComponentType) => Promise<void>\n\ntype BeforePopStateCallback = (state: any) => boolean\n\ntype ComponentLoadCancel = (() => void) | null\n\ntype HistoryMethod = 'replaceState' | 'pushState'\n\nfunction fetchNextData(\n  pathname: string,\n  query: ParsedUrlQuery | null,\n  isServerRender: boolean,\n  cb?: (...args: any) => any\n) {\n  let attempts = isServerRender ? 3 : 1\n  function getResponse(): Promise<any> {\n    return fetch(\n      formatWithValidation({\n        pathname: addBasePath(\n          // @ts-ignore __NEXT_DATA__\n          `/_next/data/${__NEXT_DATA__.buildId}${delBasePath(pathname)}.json`\n        ),\n        query,\n      }),\n      {\n        // Cookies are required to be present for Next.js' SSG \"Preview Mode\".\n        // Cookies may also be required for `getServerSideProps`.\n        //\n        // > `fetch` won’t send cookies, unless you set the credentials init\n        // > option.\n        // https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch\n        //\n        // > For maximum browser compatibility when it comes to sending &\n        // > receiving cookies, always supply the `credentials: 'same-origin'`\n        // > option instead of relying on the default.\n        // https://github.com/github/fetch#caveats\n        credentials: 'same-origin',\n      }\n    ).then((res) => {\n      if (!res.ok) {\n        if (--attempts > 0 && res.status >= 500) {\n          return getResponse()\n        }\n        throw new Error(`Failed to load static props`)\n      }\n      return res.json()\n    })\n  }\n\n  return getResponse()\n    .then((data) => {\n      return cb ? cb(data) : data\n    })\n    .catch((err: Error) => {\n      // We should only trigger a server-side transition if this was caused\n      // on a client-side transition. Otherwise, we'd get into an infinite\n      // loop.\n      if (!isServerRender) {\n        ;(err as any).code = 'PAGE_LOAD_ERROR'\n      }\n      throw err\n    })\n}\n\nexport default class Router implements BaseRouter {\n  route: string\n  pathname: string\n  query: ParsedUrlQuery\n  asPath: string\n  basePath: string\n\n  /**\n   * Map of all components loaded in `Router`\n   */\n  components: { [pathname: string]: RouteInfo }\n  // Static Data Cache\n  sdc: { [asPath: string]: object } = {}\n  sub: Subscription\n  clc: ComponentLoadCancel\n  pageLoader: any\n  _bps: BeforePopStateCallback | undefined\n  events: MittEmitter\n  _wrapApp: (App: ComponentType) => any\n  isSsr: boolean\n  isFallback: boolean\n\n  static events: MittEmitter = mitt()\n\n  constructor(\n    pathname: string,\n    query: ParsedUrlQuery,\n    as: string,\n    {\n      initialProps,\n      pageLoader,\n      App,\n      wrapApp,\n      Component,\n      err,\n      subscription,\n      isFallback,\n    }: {\n      subscription: Subscription\n      initialProps: any\n      pageLoader: any\n      Component: ComponentType\n      App: ComponentType\n      wrapApp: (App: ComponentType) => any\n      err?: Error\n      isFallback: boolean\n    }\n  ) {\n    // represents the current component key\n    this.route = toRoute(pathname)\n\n    // set up the component cache (by route keys)\n    this.components = {}\n    // We should not keep the cache, if there's an error\n    // Otherwise, this cause issues when when going back and\n    // come again to the errored page.\n    if (pathname !== '/_error') {\n      this.components[this.route] = {\n        Component,\n        props: initialProps,\n        err,\n        __N_SSG: initialProps && initialProps.__N_SSG,\n        __N_SSP: initialProps && initialProps.__N_SSP,\n      }\n    }\n\n    this.components['/_app'] = { Component: App }\n\n    // Backwards compat for Router.router.events\n    // TODO: Should be remove the following major version as it was never documented\n    this.events = Router.events\n\n    this.pageLoader = pageLoader\n    this.pathname = pathname\n    this.query = query\n    // if auto prerendered and dynamic route wait to update asPath\n    // until after mount to prevent hydration mismatch\n    this.asPath =\n      // @ts-ignore this is temporarily global (attached to window)\n      isDynamicRoute(pathname) && __NEXT_DATA__.autoExport ? pathname : as\n    this.basePath = basePath\n    this.sub = subscription\n    this.clc = null\n    this._wrapApp = wrapApp\n    // make sure to ignore extra popState in safari on navigating\n    // back from external site\n    this.isSsr = true\n\n    this.isFallback = isFallback\n\n    if (typeof window !== 'undefined') {\n      // make sure \"as\" doesn't start with double slashes or else it can\n      // throw an error as it's considered invalid\n      if (as.substr(0, 2) !== '//') {\n        // in order for `e.state` to work on the `onpopstate` event\n        // we have to register the initial route upon initialization\n        this.changeState(\n          'replaceState',\n          formatWithValidation({ pathname, query }),\n          as\n        )\n      }\n\n      window.addEventListener('popstate', this.onPopState)\n    }\n  }\n\n  // @deprecated backwards compatibility even though it's a private method.\n  static _rewriteUrlForNextExport(url: string): string {\n    if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {\n      const rewriteUrlForNextExport = require('./rewrite-url-for-export')\n        .rewriteUrlForNextExport\n      return rewriteUrlForNextExport(url)\n    } else {\n      return url\n    }\n  }\n\n  onPopState = (e: PopStateEvent): void => {\n    if (!e.state) {\n      // We get state as undefined for two reasons.\n      //  1. With older safari (< 8) and older chrome (< 34)\n      //  2. When the URL changed with #\n      //\n      // In the both cases, we don't need to proceed and change the route.\n      // (as it's already changed)\n      // But we can simply replace the state with the new changes.\n      // Actually, for (1) we don't need to nothing. But it's hard to detect that event.\n      // So, doing the following for (1) does no harm.\n      const { pathname, query } = this\n      this.changeState(\n        'replaceState',\n        formatWithValidation({ pathname, query }),\n        getURL()\n      )\n      return\n    }\n\n    // Make sure we don't re-render on initial load,\n    // can be caused by navigating back from an external site\n    if (\n      e.state &&\n      this.isSsr &&\n      e.state.as === this.asPath &&\n      parse(e.state.url).pathname === this.pathname\n    ) {\n      return\n    }\n\n    // If the downstream application returns falsy, return.\n    // They will then be responsible for handling the event.\n    if (this._bps && !this._bps(e.state)) {\n      return\n    }\n\n    const { url, as, options } = e.state\n    if (process.env.NODE_ENV !== 'production') {\n      if (typeof url === 'undefined' || typeof as === 'undefined') {\n        console.warn(\n          '`popstate` event triggered but `event.state` did not have `url` or `as` https://err.sh/vercel/next.js/popstate-state-empty'\n        )\n      }\n    }\n    this.replace(url, as, options)\n  }\n\n  update(route: string, mod: any) {\n    const Component: ComponentType = mod.default || mod\n    const data = this.components[route]\n    if (!data) {\n      throw new Error(`Cannot update unavailable route: ${route}`)\n    }\n\n    const newData = Object.assign({}, data, {\n      Component,\n      __N_SSG: mod.__N_SSG,\n      __N_SSP: mod.__N_SSP,\n    })\n    this.components[route] = newData\n\n    // pages/_app.js updated\n    if (route === '/_app') {\n      this.notify(this.components[this.route])\n      return\n    }\n\n    if (route === this.route) {\n      this.notify(newData)\n    }\n  }\n\n  reload(): void {\n    window.location.reload()\n  }\n\n  /**\n   * Go back in history\n   */\n  back() {\n    window.history.back()\n  }\n\n  /**\n   * Performs a `pushState` with arguments\n   * @param url of the route\n   * @param as masks `url` for the browser\n   * @param options object you can define `shallow` and other options\n   */\n  push(url: Url, as: Url = url, options = {}) {\n    return this.change('pushState', url, as, options)\n  }\n\n  /**\n   * Performs a `replaceState` with arguments\n   * @param url of the route\n   * @param as masks `url` for the browser\n   * @param options object you can define `shallow` and other options\n   */\n  replace(url: Url, as: Url = url, options = {}) {\n    return this.change('replaceState', url, as, options)\n  }\n\n  change(\n    method: HistoryMethod,\n    _url: Url,\n    _as: Url,\n    options: any\n  ): Promise<boolean> {\n    return new Promise((resolve, reject) => {\n      if (!options._h) {\n        this.isSsr = false\n      }\n      // marking route changes as a navigation start entry\n      if (ST) {\n        performance.mark('routeChange')\n      }\n\n      // If url and as provided as an object representation,\n      // we'll format them into the string version here.\n      let url = typeof _url === 'object' ? formatWithValidation(_url) : _url\n      let as = typeof _as === 'object' ? formatWithValidation(_as) : _as\n\n      url = addBasePath(url)\n      as = addBasePath(as)\n\n      // Add the ending slash to the paths. So, we can serve the\n      // \"<page>/index.html\" directly for the SSR page.\n      if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {\n        const rewriteUrlForNextExport = require('./rewrite-url-for-export')\n          .rewriteUrlForNextExport\n        // @ts-ignore this is temporarily global (attached to window)\n        if (__NEXT_DATA__.nextExport) {\n          as = rewriteUrlForNextExport(as)\n        }\n      }\n\n      this.abortComponentLoad(as)\n\n      // If the url change is only related to a hash change\n      // We should not proceed. We should only change the state.\n\n      // WARNING: `_h` is an internal option for handing Next.js client-side\n      // hydration. Your app should _never_ use this property. It may change at\n      // any time without notice.\n      if (!options._h && this.onlyAHashChange(as)) {\n        this.asPath = as\n        Router.events.emit('hashChangeStart', as)\n        this.changeState(method, url, as, options)\n        this.scrollToHash(as)\n        Router.events.emit('hashChangeComplete', as)\n        return resolve(true)\n      }\n\n      const { pathname, query, protocol } = parse(url, true)\n\n      if (!pathname || protocol) {\n        if (process.env.NODE_ENV !== 'production') {\n          throw new Error(\n            `Invalid href passed to router: ${url} https://err.sh/vercel/next.js/invalid-href-passed`\n          )\n        }\n        return resolve(false)\n      }\n\n      // If asked to change the current URL we should reload the current page\n      // (not location.reload() but reload getInitialProps and other Next.js stuffs)\n      // We also need to set the method = replaceState always\n      // as this should not go into the history (That's how browsers work)\n      // We should compare the new asPath to the current asPath, not the url\n      if (!this.urlIsNew(as)) {\n        method = 'replaceState'\n      }\n\n      const route = toRoute(pathname)\n      const { shallow = false } = options\n\n      if (isDynamicRoute(route)) {\n        const { pathname: asPathname } = parse(as)\n        const routeRegex = getRouteRegex(route)\n        const routeMatch = getRouteMatcher(routeRegex)(asPathname)\n        if (!routeMatch) {\n          const missingParams = Object.keys(routeRegex.groups).filter(\n            (param) => !query[param]\n          )\n\n          if (missingParams.length > 0) {\n            if (process.env.NODE_ENV !== 'production') {\n              console.warn(\n                `Mismatching \\`as\\` and \\`href\\` failed to manually provide ` +\n                  `the params: ${missingParams.join(\n                    ', '\n                  )} in the \\`href\\`'s \\`query\\``\n              )\n            }\n\n            return reject(\n              new Error(\n                `The provided \\`as\\` value (${asPathname}) is incompatible with the \\`href\\` value (${route}). ` +\n                  `Read more: https://err.sh/vercel/next.js/incompatible-href-as`\n              )\n            )\n          }\n        } else {\n          // Merge params into `query`, overwriting any specified in search\n          Object.assign(query, routeMatch)\n        }\n      }\n\n      Router.events.emit('routeChangeStart', as)\n\n      // If shallow is true and the route exists in the router cache we reuse the previous result\n      this.getRouteInfo(route, pathname, query, as, shallow).then(\n        (routeInfo) => {\n          const { error } = routeInfo\n\n          if (error && error.cancelled) {\n            return resolve(false)\n          }\n\n          Router.events.emit('beforeHistoryChange', as)\n          this.changeState(method, url, as, options)\n\n          if (process.env.NODE_ENV !== 'production') {\n            const appComp: any = this.components['/_app'].Component\n            ;(window as any).next.isPrerendered =\n              appComp.getInitialProps === appComp.origGetInitialProps &&\n              !(routeInfo.Component as any).getInitialProps\n          }\n\n          this.set(route, pathname, query, as, routeInfo).then(() => {\n            if (error) {\n              Router.events.emit('routeChangeError', error, as)\n              throw error\n            }\n\n            Router.events.emit('routeChangeComplete', as)\n            return resolve(true)\n          })\n        },\n        reject\n      )\n    })\n  }\n\n  changeState(\n    method: HistoryMethod,\n    url: string,\n    as: string,\n    options = {}\n  ): void {\n    if (process.env.NODE_ENV !== 'production') {\n      if (typeof window.history === 'undefined') {\n        console.error(`Warning: window.history is not available.`)\n        return\n      }\n\n      if (typeof window.history[method] === 'undefined') {\n        console.error(`Warning: window.history.${method} is not available`)\n        return\n      }\n    }\n\n    if (method !== 'pushState' || getURL() !== as) {\n      window.history[method](\n        {\n          url,\n          as,\n          options,\n        },\n        // Most browsers currently ignores this parameter, although they may use it in the future.\n        // Passing the empty string here should be safe against future changes to the method.\n        // https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState\n        '',\n        as\n      )\n    }\n  }\n\n  getRouteInfo(\n    route: string,\n    pathname: string,\n    query: any,\n    as: string,\n    shallow: boolean = false\n  ): Promise<RouteInfo> {\n    const cachedRouteInfo = this.components[route]\n\n    // If there is a shallow route transition possible\n    // If the route is already rendered on the screen.\n    if (shallow && cachedRouteInfo && this.route === route) {\n      return Promise.resolve(cachedRouteInfo)\n    }\n\n    const handleError = (\n      err: Error & { code: any; cancelled: boolean },\n      loadErrorFail?: boolean\n    ) => {\n      return new Promise((resolve) => {\n        if (err.code === 'PAGE_LOAD_ERROR' || loadErrorFail) {\n          // If we can't load the page it could be one of following reasons\n          //  1. Page doesn't exists\n          //  2. Page does exist in a different zone\n          //  3. Internal error while loading the page\n\n          // So, doing a hard reload is the proper way to deal with this.\n          window.location.href = as\n\n          // Changing the URL doesn't block executing the current code path.\n          // So, we need to mark it as a cancelled error and stop the routing logic.\n          err.cancelled = true\n          // @ts-ignore TODO: fix the control flow here\n          return resolve({ error: err })\n        }\n\n        if (err.cancelled) {\n          // @ts-ignore TODO: fix the control flow here\n          return resolve({ error: err })\n        }\n\n        resolve(\n          this.fetchComponent('/_error')\n            .then((res) => {\n              const { page: Component } = res\n              const routeInfo: RouteInfo = { Component, err }\n              return new Promise((resolve) => {\n                this.getInitialProps(Component, {\n                  err,\n                  pathname,\n                  query,\n                } as any).then(\n                  (props) => {\n                    routeInfo.props = props\n                    routeInfo.error = err\n                    resolve(routeInfo)\n                  },\n                  (gipErr) => {\n                    console.error(\n                      'Error in error page `getInitialProps`: ',\n                      gipErr\n                    )\n                    routeInfo.error = err\n                    routeInfo.props = {}\n                    resolve(routeInfo)\n                  }\n                )\n              }) as Promise<RouteInfo>\n            })\n            .catch((err) => handleError(err, true))\n        )\n      }) as Promise<RouteInfo>\n    }\n\n    return (new Promise((resolve, reject) => {\n      if (cachedRouteInfo) {\n        return resolve(cachedRouteInfo)\n      }\n\n      this.fetchComponent(route).then(\n        (res) =>\n          resolve({\n            Component: res.page,\n            __N_SSG: res.mod.__N_SSG,\n            __N_SSP: res.mod.__N_SSP,\n          }),\n        reject\n      )\n    }) as Promise<RouteInfo>)\n      .then((routeInfo: RouteInfo) => {\n        const { Component, __N_SSG, __N_SSP } = routeInfo\n\n        if (process.env.NODE_ENV !== 'production') {\n          const { isValidElementType } = require('react-is')\n          if (!isValidElementType(Component)) {\n            throw new Error(\n              `The default export is not a React Component in page: \"${pathname}\"`\n            )\n          }\n        }\n\n        return this._getData<RouteInfo>(() =>\n          __N_SSG\n            ? this._getStaticData(as)\n            : __N_SSP\n            ? this._getServerData(as)\n            : this.getInitialProps(\n                Component,\n                // we provide AppTree later so this needs to be `any`\n                {\n                  pathname,\n                  query,\n                  asPath: as,\n                } as any\n              )\n        ).then((props) => {\n          routeInfo.props = props\n          this.components[route] = routeInfo\n          return routeInfo\n        })\n      })\n      .catch(handleError)\n  }\n\n  set(\n    route: string,\n    pathname: string,\n    query: any,\n    as: string,\n    data: RouteInfo\n  ): Promise<void> {\n    this.isFallback = false\n\n    this.route = route\n    this.pathname = pathname\n    this.query = query\n    this.asPath = as\n    return this.notify(data)\n  }\n\n  /**\n   * Callback to execute before replacing router state\n   * @param cb callback to be executed\n   */\n  beforePopState(cb: BeforePopStateCallback) {\n    this._bps = cb\n  }\n\n  onlyAHashChange(as: string): boolean {\n    if (!this.asPath) return false\n    const [oldUrlNoHash, oldHash] = this.asPath.split('#')\n    const [newUrlNoHash, newHash] = as.split('#')\n\n    // Makes sure we scroll to the provided hash if the url/hash are the same\n    if (newHash && oldUrlNoHash === newUrlNoHash && oldHash === newHash) {\n      return true\n    }\n\n    // If the urls are change, there's more than a hash change\n    if (oldUrlNoHash !== newUrlNoHash) {\n      return false\n    }\n\n    // If the hash has changed, then it's a hash only change.\n    // This check is necessary to handle both the enter and\n    // leave hash === '' cases. The identity case falls through\n    // and is treated as a next reload.\n    return oldHash !== newHash\n  }\n\n  scrollToHash(as: string): void {\n    const [, hash] = as.split('#')\n    // Scroll to top if the hash is just `#` with no value\n    if (hash === '') {\n      window.scrollTo(0, 0)\n      return\n    }\n\n    // First we check if the element by id is found\n    const idEl = document.getElementById(hash)\n    if (idEl) {\n      idEl.scrollIntoView()\n      return\n    }\n    // If there's no element with the id, we check the `name` property\n    // To mirror browsers\n    const nameEl = document.getElementsByName(hash)[0]\n    if (nameEl) {\n      nameEl.scrollIntoView()\n    }\n  }\n\n  urlIsNew(asPath: string): boolean {\n    return this.asPath !== asPath\n  }\n\n  /**\n   * Prefetch page code, you may wait for the data during page rendering.\n   * This feature only works in production!\n   * @param url the href of prefetched page\n   * @param asPath the as path of the prefetched page\n   */\n  prefetch(\n    url: string,\n    asPath: string = url,\n    options: PrefetchOptions = {}\n  ): Promise<void> {\n    return new Promise((resolve, reject) => {\n      const { pathname, protocol } = parse(url)\n\n      if (!pathname || protocol) {\n        if (process.env.NODE_ENV !== 'production') {\n          throw new Error(\n            `Invalid href passed to router: ${url} https://err.sh/vercel/next.js/invalid-href-passed`\n          )\n        }\n        return\n      }\n\n      // Prefetch is not supported in development mode because it would trigger on-demand-entries\n      if (process.env.NODE_ENV !== 'production') {\n        return\n      }\n      const route = delBasePath(toRoute(pathname))\n      Promise.all([\n        this.pageLoader.prefetchData(url, delBasePath(asPath)),\n        this.pageLoader[options.priority ? 'loadPage' : 'prefetch'](route),\n      ]).then(() => resolve(), reject)\n    })\n  }\n\n  async fetchComponent(route: string): Promise<ComponentRes> {\n    let cancelled = false\n    const cancel = (this.clc = () => {\n      cancelled = true\n    })\n    route = delBasePath(route)\n\n    const componentResult = await this.pageLoader.loadPage(route)\n\n    if (cancelled) {\n      const error: any = new Error(\n        `Abort fetching component for route: \"${route}\"`\n      )\n      error.cancelled = true\n      throw error\n    }\n\n    if (cancel === this.clc) {\n      this.clc = null\n    }\n\n    return componentResult\n  }\n\n  _getData<T>(fn: () => Promise<T>): Promise<T> {\n    let cancelled = false\n    const cancel = () => {\n      cancelled = true\n    }\n    this.clc = cancel\n    return fn().then((data) => {\n      if (cancel === this.clc) {\n        this.clc = null\n      }\n\n      if (cancelled) {\n        const err: any = new Error('Loading initial props cancelled')\n        err.cancelled = true\n        throw err\n      }\n\n      return data\n    })\n  }\n\n  _getStaticData = (asPath: string): Promise<object> => {\n    const pathname = prepareRoute(parse(asPath).pathname!)\n\n    return process.env.NODE_ENV === 'production' && this.sdc[pathname]\n      ? Promise.resolve(this.sdc[pathname])\n      : fetchNextData(\n          pathname,\n          null,\n          this.isSsr,\n          (data) => (this.sdc[pathname] = data)\n        )\n  }\n\n  _getServerData = (asPath: string): Promise<object> => {\n    let { pathname, query } = parse(asPath, true)\n    pathname = prepareRoute(pathname!)\n    return fetchNextData(pathname, query, this.isSsr)\n  }\n\n  getInitialProps(\n    Component: ComponentType,\n    ctx: NextPageContext\n  ): Promise<any> {\n    const { Component: App } = this.components['/_app']\n    const AppTree = this._wrapApp(App)\n    ctx.AppTree = AppTree\n    return loadGetInitialProps<AppContextType<Router>>(App, {\n      AppTree,\n      Component,\n      router: this,\n      ctx,\n    })\n  }\n\n  abortComponentLoad(as: string): void {\n    if (this.clc) {\n      const e = new Error('Route Cancelled')\n      ;(e as any).cancelled = true\n      Router.events.emit('routeChangeError', e, as)\n      this.clc()\n      this.clc = null\n    }\n  }\n\n  notify(data: RouteInfo): Promise<void> {\n    return this.sub(data, this.components['/_app'].Component)\n  }\n}\n"]},"metadata":{},"sourceType":"script"}