UNPKG

next-batch-router

Version:

An alternative to next/router that batches push and replace calls. It allows for multiple pushes without overwriting each other.

50 lines (49 loc) 2.1 kB
export declare namespace BatchRouterTypes { type NextQueryValue = string | string[] | undefined; type WriteQueryValue = NextQueryValue | number | boolean | (string | number | boolean)[] | null; type NextQueryObject = Record<string, NextQueryValue>; type WriteQueryObject = Record<string, WriteQueryValue>; type SetQueryAction = WriteQueryObject | ((prev: NextQueryObject) => WriteQueryObject); type QueueItem = { query: SetQueryAction; asQuery: SetQueryAction; hash?: string | null; }; type PartialUrlObject = { query?: SetQueryAction; hash?: string | null; }; type TransitionOptions = { shallow?: boolean; locale?: string; scroll?: boolean; }; } /** * Subset of next/router that allows for multiple consecutive query string changes by batch updating and functinoal update. * * `push` and `replace` calls are merged together and applied at the start of the next render cycle. * * `push` and `replace` calls only take `query` object and `hash` of the route. * Use original next/router for changing pathname or inserting query as a string. * * Unlike next/router, it preserves hash unless overwritten as `null`. */ export declare type BatchRouter = Pick<BatchRouterCore, "push" | "replace">; export declare class BatchRouterCore implements BatchRouter { private forceRender; private queue; private pushHistory; private shallow; private scroll; private locale; private renderTriggered; private routePromise?; private resolveRoutePromise?; constructor(forceRender: () => void); push(url: BatchRouterTypes.PartialUrlObject, as?: BatchRouterTypes.PartialUrlObject, options?: BatchRouterTypes.TransitionOptions): Promise<boolean | undefined>; replace(url: BatchRouterTypes.PartialUrlObject, as?: BatchRouterTypes.PartialUrlObject, options?: BatchRouterTypes.TransitionOptions): Promise<boolean | undefined>; private change; flush(): Promise<boolean | undefined>; private clear; }