UNPKG

create-dan

Version:

Dan frameworks

1 lines 58.4 kB
{"ast":null,"code":"\"use strict\";\n\nvar _Object$assign = require(\"@babel/runtime-corejs2/core-js/object/assign\");\n\nvar _Promise = require(\"@babel/runtime-corejs2/core-js/promise\");\n\nvar _Object$defineProperty = require(\"@babel/runtime-corejs2/core-js/object/define-property\");\n\nvar __importDefault = this && this.__importDefault || function (mod) {\n return mod && mod.__esModule ? mod : {\n \"default\": mod\n };\n};\n\n_Object$defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nconst url_1 = require(\"url\");\n\nconst mitt_1 = __importDefault(require(\"../mitt\"));\n\nconst utils_1 = require(\"../utils\");\n\nconst is_dynamic_1 = require(\"./utils/is-dynamic\");\n\nconst route_matcher_1 = require(\"./utils/route-matcher\");\n\nconst route_regex_1 = require(\"./utils/route-regex\");\n\nfunction addBasePath(path) {\n // @ts-ignore variable is always a string\n const p = process.env.__NEXT_ROUTER_BASEPATH;\n return path.indexOf(p) !== 0 ? p + path : path;\n}\n\nfunction toRoute(path) {\n return path.replace(/\\/$/, '') || '/';\n}\n\nclass Router {\n constructor(pathname, query, as, {\n initialProps,\n pageLoader,\n App,\n wrapApp,\n Component,\n err,\n subscription\n }) {\n // Static Data Cache\n this.sdc = {};\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', utils_1.formatWithValidation({\n pathname,\n query\n }), utils_1.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.url === this.pathname && e.state.as === this.asPath) {\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/zeit/next.js/popstate-state-empty');\n }\n }\n\n this.replace(url, as, options);\n };\n\n this._getStaticData = (asPath, _cachedData) => {\n let pathname = url_1.parse(asPath).pathname;\n pathname = !pathname || pathname === '/' ? '/index' : pathname;\n return false && (_cachedData = this.sdc[pathname]) ? _Promise.resolve(_cachedData) : fetch( // @ts-ignore __NEXT_DATA__\n `/_next/data/${__NEXT_DATA__.buildId}${pathname}.json`).then(res => {\n if (!res.ok) {\n throw new Error(`Failed to load static props`);\n }\n\n return res.json();\n }).then(data => {\n this.sdc[pathname] = data;\n return data;\n }).catch(err => {\n ;\n err.code = 'PAGE_LOAD_ERROR';\n throw err;\n });\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 }\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 // @ts-ignore backwards compatibility\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 is_dynamic_1.isDynamicRoute(pathname) && __NEXT_DATA__.autoExport ? pathname : as;\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\n if (false) {\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', utils_1.formatWithValidation({\n pathname,\n query\n }), as);\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(_Object$assign({}, data), {\n Component\n });\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_1.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 const url = typeof _url === 'object' ? utils_1.formatWithValidation(_url) : _url;\n let as = typeof _as === 'object' ? utils_1.formatWithValidation(_as) : _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, addBasePath(as));\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 } = url_1.parse(url, true);\n\n if (!pathname || protocol) {\n if (true) {\n throw new Error(`Invalid href passed to router: ${url} https://err.sh/zeit/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 } // @ts-ignore pathname is always a string\n\n\n const route = toRoute(pathname);\n const {\n shallow = false\n } = options;\n\n if (is_dynamic_1.isDynamicRoute(route)) {\n const {\n pathname: asPathname\n } = url_1.parse(as);\n const routeMatch = route_matcher_1.getRouteMatcher(route_regex_1.getRouteRegex(route))(asPathname);\n\n if (!routeMatch) {\n const error = `The provided \\`as\\` value (${asPathname}) is incompatible with the \\`href\\` value (${route}). ` + `Read more: https://err.sh/zeit/next.js/incompatible-href-as`;\n\n if (true) {\n throw new Error(error);\n } else {\n console.error(error);\n }\n\n return resolve(false);\n } // Merge params into `query`, overwriting any specified in search\n\n\n _Object$assign(query, routeMatch);\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 // @ts-ignore pathname is always a string\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, addBasePath(as), options);\n const hash = window.location.hash.substring(1);\n\n if (true) {\n const appComp = this.components['/_app'].Component;\n window.next.isPrerendered = appComp.getInitialProps === appComp.origGetInitialProps && !routeInfo.Component.getInitialProps;\n } // @ts-ignore pathname is always defined\n\n\n this.set(route, pathname, query, as, _Object$assign(_Object$assign({}, routeInfo), {\n hash\n }));\n\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 }, 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 } // @ts-ignore method should always exist on history\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' || utils_1.getURL() !== as) {\n // @ts-ignore method should always exist on history\n window.history[method]({\n url,\n as,\n options\n }, null, 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 return new _Promise((resolve, reject) => {\n if (cachedRouteInfo) {\n return resolve(cachedRouteInfo);\n }\n\n this.fetchComponent(route).then(Component => resolve({\n Component\n }), reject);\n }).then(routeInfo => {\n const {\n Component\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(() => Component.__N_SSG ? this._getStaticData(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(err => {\n return new _Promise(resolve => {\n if (err.code === 'PAGE_LOAD_ERROR') {\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(Component => {\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 }));\n });\n });\n }\n\n set(route, pathname, query, as, data) {\n this.route = route;\n this.pathname = pathname;\n this.query = query;\n this.asPath = as;\n 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 of prefetched `page`\n */\n\n\n prefetch(url) {\n return new _Promise((resolve, reject) => {\n const {\n pathname,\n protocol\n } = url_1.parse(url);\n\n if (!pathname || protocol) {\n if (true) {\n throw new Error(`Invalid href passed to router: ${url} https://err.sh/zeit/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 } // @ts-ignore pathname is always defined\n\n\n const route = toRoute(pathname);\n this.pageLoader.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 const Component = 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 Component;\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 utils_1.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 this.sub(data, this.components['/_app'].Component);\n }\n\n}\n\nexports.default = Router;\nRouter.events = mitt_1.default();","map":{"version":3,"sources":["/Users/sbourgal/Documents/Projets/DAN/dan-framework/template/node_modules/next/dist/next-server/lib/router/router.js"],"names":["__importDefault","mod","__esModule","exports","value","url_1","require","mitt_1","utils_1","is_dynamic_1","route_matcher_1","route_regex_1","addBasePath","path","p","process","env","__NEXT_ROUTER_BASEPATH","indexOf","toRoute","replace","Router","constructor","pathname","query","as","initialProps","pageLoader","App","wrapApp","Component","err","subscription","sdc","onPopState","e","state","changeState","formatWithValidation","getURL","isSsr","url","asPath","_bps","options","console","warn","_getStaticData","_cachedData","parse","resolve","fetch","__NEXT_DATA__","buildId","then","res","ok","Error","json","data","catch","code","route","components","props","events","isDynamicRoute","autoExport","sub","clc","_wrapApp","window","addEventListener","_rewriteUrlForNextExport","__NEXT_EXPORT_TRAILING_SLASH","rewriteUrlForNextExport","update","default","newData","notify","reload","location","back","history","push","change","method","_url","_as","reject","_h","ST","performance","mark","nextExport","abortComponentLoad","onlyAHashChange","emit","scrollToHash","protocol","urlIsNew","shallow","asPathname","routeMatch","getRouteMatcher","getRouteRegex","error","getRouteInfo","routeInfo","cancelled","hash","substring","appComp","next","isPrerendered","getInitialProps","origGetInitialProps","set","cachedRouteInfo","fetchComponent","isValidElementType","_getData","__N_SSG","href","gipErr","beforePopState","cb","oldUrlNoHash","oldHash","split","newUrlNoHash","newHash","scrollTo","idEl","document","getElementById","scrollIntoView","nameEl","getElementsByName","prefetch","cancel","loadPage","fn","ctx","AppTree","loadGetInitialProps","router"],"mappings":"AAAA;;;;;;;;AACA,IAAIA,eAAe,GAAI,QAAQ,KAAKA,eAAd,IAAkC,UAAUC,GAAV,EAAe;AACnE,SAAQA,GAAG,IAAIA,GAAG,CAACC,UAAZ,GAA0BD,GAA1B,GAAgC;AAAE,eAAWA;AAAb,GAAvC;AACH,CAFD;;AAGA,uBAAsBE,OAAtB,EAA+B,YAA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mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst url_1 = require(\"url\");\nconst mitt_1 = __importDefault(require(\"../mitt\"));\nconst utils_1 = require(\"../utils\");\nconst is_dynamic_1 = require(\"./utils/is-dynamic\");\nconst route_matcher_1 = require(\"./utils/route-matcher\");\nconst route_regex_1 = require(\"./utils/route-regex\");\nfunction addBasePath(path) {\n // @ts-ignore variable is always a string\n const p = process.env.__NEXT_ROUTER_BASEPATH;\n return path.indexOf(p) !== 0 ? p + path : path;\n}\nfunction toRoute(path) {\n return path.replace(/\\/$/, '') || '/';\n}\nclass Router {\n constructor(pathname, query, as, { initialProps, pageLoader, App, wrapApp, Component, err, subscription, }) {\n // Static Data Cache\n this.sdc = {};\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 { pathname, query } = this;\n this.changeState('replaceState', utils_1.formatWithValidation({ pathname, query }), utils_1.getURL());\n return;\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 (e.state &&\n this.isSsr &&\n e.state.url === this.pathname &&\n e.state.as === this.asPath) {\n return;\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 const { url, as, options } = e.state;\n if (process.env.NODE_ENV !== 'production') {\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/zeit/next.js/popstate-state-empty');\n }\n }\n this.replace(url, as, options);\n };\n this._getStaticData = (asPath, _cachedData) => {\n let pathname = url_1.parse(asPath).pathname;\n pathname = !pathname || pathname === '/' ? '/index' : pathname;\n return process.env.NODE_ENV === 'production' &&\n (_cachedData = this.sdc[pathname])\n ? Promise.resolve(_cachedData)\n : fetch(\n // @ts-ignore __NEXT_DATA__\n `/_next/data/${__NEXT_DATA__.buildId}${pathname}.json`)\n .then(res => {\n if (!res.ok) {\n throw new Error(`Failed to load static props`);\n }\n return res.json();\n })\n .then(data => {\n this.sdc[pathname] = data;\n return data;\n })\n .catch((err) => {\n ;\n err.code = 'PAGE_LOAD_ERROR';\n throw err;\n });\n };\n // represents the current component key\n this.route = toRoute(pathname);\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] = { Component, props: initialProps, err };\n }\n this.components['/_app'] = { Component: App };\n // Backwards compat for Router.router.events\n // TODO: Should be remove the following major version as it was never documented\n // @ts-ignore backwards compatibility\n this.events = Router.events;\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 is_dynamic_1.isDynamicRoute(pathname) && __NEXT_DATA__.autoExport ? pathname : as;\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 if (typeof window !== 'undefined') {\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', utils_1.formatWithValidation({ pathname, query }), as);\n window.addEventListener('popstate', this.onPopState);\n }\n }\n // @deprecated backwards compatibility even though it's a private method.\n static _rewriteUrlForNextExport(url) {\n if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {\n const rewriteUrlForNextExport = require('./rewrite-url-for-export')\n .rewriteUrlForNextExport;\n return rewriteUrlForNextExport(url);\n }\n else {\n return url;\n }\n }\n update(route, mod) {\n const Component = mod.default || mod;\n const data = this.components[route];\n if (!data) {\n throw new Error(`Cannot update unavailable route: ${route}`);\n }\n const newData = Object.assign(Object.assign({}, data), { Component });\n this.components[route] = newData;\n // pages/_app.js updated\n if (route === '/_app') {\n this.notify(this.components[this.route]);\n return;\n }\n if (route === this.route) {\n this.notify(newData);\n }\n }\n reload() {\n window.location.reload();\n }\n /**\n * Go back in history\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 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 replace(url, as = url, options = {}) {\n return this.change('replaceState', url, as, options);\n }\n change(method, _url, _as, options) {\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 (utils_1.ST) {\n performance.mark('routeChange');\n }\n // If url and as provided as an object representation,\n // we'll format them into the string version here.\n const url = typeof _url === 'object' ? utils_1.formatWithValidation(_url) : _url;\n let as = typeof _as === 'object' ? utils_1.formatWithValidation(_as) : _as;\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 this.abortComponentLoad(as);\n // 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 if (!options._h && this.onlyAHashChange(as)) {\n this.asPath = as;\n Router.events.emit('hashChangeStart', as);\n this.changeState(method, url, addBasePath(as));\n this.scrollToHash(as);\n Router.events.emit('hashChangeComplete', as);\n return resolve(true);\n }\n const { pathname, query, protocol } = url_1.parse(url, true);\n if (!pathname || protocol) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(`Invalid href passed to router: ${url} https://err.sh/zeit/next.js/invalid-href-passed`);\n }\n return resolve(false);\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 // @ts-ignore pathname is always a string\n const route = toRoute(pathname);\n const { shallow = false } = options;\n if (is_dynamic_1.isDynamicRoute(route)) {\n const { pathname: asPathname } = url_1.parse(as);\n const routeMatch = route_matcher_1.getRouteMatcher(route_regex_1.getRouteRegex(route))(asPathname);\n if (!routeMatch) {\n const error = `The provided \\`as\\` value (${asPathname}) is incompatible with the \\`href\\` value (${route}). ` +\n `Read more: https://err.sh/zeit/next.js/incompatible-href-as`;\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(error);\n }\n else {\n console.error(error);\n }\n return resolve(false);\n }\n // Merge params into `query`, overwriting any specified in search\n Object.assign(query, routeMatch);\n }\n Router.events.emit('routeChangeStart', as);\n // If shallow is true and the route exists in the router cache we reuse the previous result\n // @ts-ignore pathname is always a string\n this.getRouteInfo(route, pathname, query, as, shallow).then(routeInfo => {\n const { error } = routeInfo;\n if (error && error.cancelled) {\n return resolve(false);\n }\n Router.events.emit('beforeHistoryChange', as);\n this.changeState(method, url, addBasePath(as), options);\n const hash = window.location.hash.substring(1);\n if (process.env.NODE_ENV !== 'production') {\n const appComp = this.components['/_app'].Component;\n window.next.isPrerendered =\n appComp.getInitialProps === appComp.origGetInitialProps &&\n !routeInfo.Component.getInitialProps;\n }\n // @ts-ignore pathname is always defined\n this.set(route, pathname, query, as, Object.assign(Object.assign({}, routeInfo), { hash }));\n if (error) {\n Router.events.emit('routeChangeError', error, as);\n throw error;\n }\n Router.events.emit('routeChangeComplete', as);\n return resolve(true);\n }, reject);\n });\n }\n changeState(method, url, as, options = {}) {\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 // @ts-ignore method should always exist on history\n if (typeof window.history[method] === 'undefined') {\n console.error(`Warning: window.history.${method} is not available`);\n return;\n }\n }\n if (method !== 'pushState' || utils_1.getURL() !== as) {\n // @ts-ignore method should always exist on history\n window.history[method]({\n url,\n as,\n options,\n