raviger
Version:
React routing with hooks
46 lines (45 loc) • 1.77 kB
TypeScript
export interface RavigerLocation {
/** The current path; alias of `pathname` */
path: string | null;
/** The current path; alias of `path` */
pathname: string | null;
/** The full path, ignores any `basePath` in the context */
fullPath: string;
basePath?: string;
search: string;
hash: string;
host: string;
hostname: string;
href: string;
origin: string;
}
export interface RavigerHistory {
scrollRestoration: 'auto' | 'manual';
state: unknown;
}
export interface LocationChangeSetFn {
(location: RavigerLocation): void;
}
export interface LocationChangeOptionParams {
inheritBasePath?: boolean;
basePath?: string;
isActive?: boolean | (() => boolean);
onInitial?: boolean;
}
export declare function usePath(basePath?: string): string | null;
export declare function useBasePath(): string;
export declare function useFullPath(): string;
export declare function useHash({ stripHash }?: {
stripHash?: boolean | undefined;
}): string;
export declare function getCurrentPath(): string;
export declare function getCurrentHash(): string;
export declare function useLocationChange(setFn: LocationChangeSetFn, { inheritBasePath, basePath, isActive, onInitial, }?: LocationChangeOptionParams): void;
export declare function useHistory(): RavigerHistory;
/**
* Returns the current path after decoding. If basePath is provided it will be removed from the front of the path.
* If basePath is provided and the path does not begin with it will return null
* @param {string} basePath basePath, if any
* @return {string | null} returns path with basePath prefix removed, or null if basePath is provided and missing
*/
export declare function getFormattedPath(basePath: string): string | null;