///
import { ParsedUrlQuery } from 'querystring';
import { ComponentType } from 'react';
import { UrlObject } from 'url';
import { GoodPageCache, StyleSheetTuple } from '../../../client/page-loader';
import { MittEmitter } from '../mitt';
import { NextPageContext } from '../utils';
interface TransitionOptions {
shallow?: boolean;
}
interface NextHistoryState {
url: string;
as: string;
options: TransitionOptions;
}
export declare function hasBasePath(path: string): boolean;
export declare function addBasePath(path: string): string;
export declare function delBasePath(path: string): string;
/**
* Detects whether a given url is routable by the Next.js router (browser only).
*/
export declare function isLocalURL(url: string): boolean;
declare type Url = UrlObject | string;
/**
* Resolves a given hyperlink with a certain router state (basePath not included).
* Preserves absolute urls.
*/
export declare function resolveHref(currentPath: string, href: Url): string;
export declare function markLoadingError(err: Error): Error;
export declare type BaseRouter = {
route: string;
pathname: string;
query: ParsedUrlQuery;
asPath: string;
basePath: string;
};
export declare type NextRouter = BaseRouter & Pick;
export declare type PrefetchOptions = {
priority?: boolean;
};
export declare type PrivateRouteInfo = {
Component: ComponentType;
styleSheets: StyleSheetTuple[];
__N_SSG?: boolean;
__N_SSP?: boolean;
props?: Record;
err?: Error;
error?: any;
};
export declare type AppProps = Pick & {
router: Router;
} & Record;
export declare type AppComponent = ComponentType;
declare type Subscription = (data: PrivateRouteInfo, App: AppComponent) => Promise;
declare type BeforePopStateCallback = (state: NextHistoryState) => boolean;
declare type ComponentLoadCancel = (() => void) | null;
declare type HistoryMethod = 'replaceState' | 'pushState';
export default class Router implements BaseRouter {
route: string;
pathname: string;
query: ParsedUrlQuery;
asPath: string;
basePath: string;
/**
* Map of all components loaded in `Router`
*/
components: {
[pathname: string]: PrivateRouteInfo;
};
sdc: {
[asPath: string]: object;
};
sub: Subscription;
clc: ComponentLoadCancel;
pageLoader: any;
_bps: BeforePopStateCallback | undefined;
events: MittEmitter;
_wrapApp: (App: AppComponent) => any;
isSsr: boolean;
isFallback: boolean;
_inFlightRoute?: string;
_shallow?: boolean;
static events: MittEmitter;
constructor(pathname: string, query: ParsedUrlQuery, as: string, { initialProps, pageLoader, App, wrapApp, Component, initialStyleSheets, err, subscription, isFallback, }: {
subscription: Subscription;
initialProps: any;
pageLoader: any;
Component: ComponentType;
initialStyleSheets: StyleSheetTuple[];
App: AppComponent;
wrapApp: (App: AppComponent) => any;
err?: Error;
isFallback: boolean;
});
onPopState: (e: PopStateEvent) => void;
reload(): void;
/**
* Go back in history
*/
back(): void;
/**
* Performs a `pushState` with arguments
* @param url of the route
* @param as masks `url` for the browser
* @param options object you can define `shallow` and other options
*/
push(url: Url, as?: Url, options?: TransitionOptions): Promise;
/**
* Performs a `replaceState` with arguments
* @param url of the route
* @param as masks `url` for the browser
* @param options object you can define `shallow` and other options
*/
replace(url: Url, as?: Url, options?: TransitionOptions): Promise;
change(method: HistoryMethod, url: string, as: string, options: TransitionOptions): Promise;
changeState(method: HistoryMethod, url: string, as: string, options?: TransitionOptions): void;
handleRouteInfoError(err: Error & {
code: any;
cancelled: boolean;
}, pathname: string, query: ParsedUrlQuery, as: string, loadErrorFail?: boolean): Promise;
getRouteInfo(route: string, pathname: string, query: any, as: string, shallow?: boolean): Promise;
set(route: string, pathname: string, query: ParsedUrlQuery, as: string, data: PrivateRouteInfo): Promise;
/**
* Callback to execute before replacing router state
* @param cb callback to be executed
*/
beforePopState(cb: BeforePopStateCallback): void;
onlyAHashChange(as: string): boolean;
scrollToHash(as: string): void;
urlIsNew(asPath: string): boolean;
_resolveHref(parsedHref: UrlObject, pages: string[]): UrlObject;
/**
* Prefetch page code, you may wait for the data during page rendering.
* This feature only works in production!
* @param url the href of prefetched page
* @param asPath the as path of the prefetched page
*/
prefetch(url: string, asPath?: string, options?: PrefetchOptions): Promise;
fetchComponent(route: string): Promise;
_getData(fn: () => Promise): Promise;
_getStaticData(dataHref: string): Promise