Server: Phase 2 (REVIEW not respected yet)
This commit is contained in:
1 parent
5d16ded553
commit
142b47674d
4271 files changed
+1203269
No files matched your search
+120
@@ -0,0 +1,120 @@
|
||||
export interface NavigateOptions {
|
||||
ignoreBlocker?: boolean;
|
||||
}
|
||||
type SubscriberHistoryAction = {
|
||||
type: Exclude<HistoryAction, 'GO'>;
|
||||
} | {
|
||||
type: 'GO';
|
||||
index: number;
|
||||
};
|
||||
type SubscriberArgs = {
|
||||
location: HistoryLocation;
|
||||
action: SubscriberHistoryAction;
|
||||
};
|
||||
export interface RouterHistory {
|
||||
location: HistoryLocation;
|
||||
length: number;
|
||||
subscribers: Set<(opts: SubscriberArgs) => void>;
|
||||
subscribe: (cb: (opts: SubscriberArgs) => void) => () => void;
|
||||
push: (path: string, state?: any, navigateOpts?: NavigateOptions) => void;
|
||||
replace: (path: string, state?: any, navigateOpts?: NavigateOptions) => void;
|
||||
go: (index: number, navigateOpts?: NavigateOptions) => void;
|
||||
back: (navigateOpts?: NavigateOptions) => void;
|
||||
forward: (navigateOpts?: NavigateOptions) => void;
|
||||
canGoBack: () => boolean;
|
||||
createHref: (href: string) => string;
|
||||
block: (blocker: NavigationBlocker) => () => void;
|
||||
flush: () => void;
|
||||
destroy: () => void;
|
||||
notify: (action: SubscriberHistoryAction) => void;
|
||||
_getBlockers: () => Array<NavigationBlocker>;
|
||||
_ignoreSubscribers?: boolean;
|
||||
_ignoreNextBeforeUnload?: (href: string) => void;
|
||||
}
|
||||
export interface HistoryLocation extends ParsedPath {
|
||||
state: ParsedHistoryState;
|
||||
}
|
||||
export interface ParsedPath {
|
||||
href: string;
|
||||
pathname: string;
|
||||
search: string;
|
||||
hash: string;
|
||||
}
|
||||
export interface HistoryState {
|
||||
}
|
||||
export type ParsedHistoryState = HistoryState & {
|
||||
key?: string;
|
||||
__TSR_key?: string;
|
||||
__TSR_index: number;
|
||||
};
|
||||
type ShouldAllowNavigation = any;
|
||||
export type HistoryAction = 'PUSH' | 'REPLACE' | 'FORWARD' | 'BACK' | 'GO';
|
||||
export type BlockerFnArgs = {
|
||||
currentLocation: HistoryLocation;
|
||||
nextLocation: HistoryLocation;
|
||||
action: HistoryAction;
|
||||
};
|
||||
export type BlockerFn = (args: BlockerFnArgs) => Promise<ShouldAllowNavigation> | ShouldAllowNavigation;
|
||||
export type NavigationBlocker = {
|
||||
blockerFn: BlockerFn;
|
||||
enableBeforeUnload?: (() => boolean) | boolean;
|
||||
};
|
||||
export declare function normalizeProtocolRelative(url: string): string;
|
||||
export declare function createHistory(opts: {
|
||||
getLocation: () => HistoryLocation;
|
||||
getLength: () => number;
|
||||
pushState: (path: string, state: any) => void;
|
||||
replaceState: (path: string, state: any) => void;
|
||||
go: (n: number, ignoreBlocker: boolean) => void;
|
||||
back: (ignoreBlocker: boolean) => void;
|
||||
forward: (ignoreBlocker: boolean) => void;
|
||||
createHref: (path: string) => string;
|
||||
flush?: () => void;
|
||||
destroy?: () => void;
|
||||
onBlocked?: () => void;
|
||||
getBlockers?: () => Array<NavigationBlocker>;
|
||||
setBlockers?: (blockers: Array<NavigationBlocker>) => void;
|
||||
notifyOnIndexChange?: boolean;
|
||||
}): RouterHistory;
|
||||
/**
|
||||
* Creates a history object that can be used to interact with the browser's
|
||||
* navigation. This is a lightweight API wrapping the browser's native methods.
|
||||
* It is designed to work with TanStack Router, but could be used as a standalone API as well.
|
||||
* IMPORTANT: This API implements history throttling via a microtask to prevent
|
||||
* excessive calls to the history API. In some browsers, calling history.pushState or
|
||||
* history.replaceState in quick succession can cause the browser to ignore subsequent
|
||||
* calls. This API smooths out those differences and ensures that your application
|
||||
* state will *eventually* match the browser state. In most cases, this is not a problem,
|
||||
* but if you need to ensure that the browser state is up to date, you can use the
|
||||
* `history.flush` method to immediately flush all pending state changes to the browser URL.
|
||||
* @param opts
|
||||
* @param opts.getHref A function that returns the current href (path + search + hash)
|
||||
* @param opts.createHref A function that takes a path and returns a href (path + search + hash)
|
||||
* @returns A history instance
|
||||
*/
|
||||
export declare function createBrowserHistory(opts?: {
|
||||
parseLocation?: () => HistoryLocation;
|
||||
createHref?: (path: string) => string;
|
||||
window?: any;
|
||||
}): RouterHistory;
|
||||
/**
|
||||
* Create a hash-based history implementation.
|
||||
* Useful for static hosts or environments without server URL rewriting.
|
||||
* @link https://tanstack.com/router/latest/docs/framework/react/guide/history-types
|
||||
*/
|
||||
export declare function createHashHistory(opts?: {
|
||||
window?: any;
|
||||
}): RouterHistory;
|
||||
/**
|
||||
* Create an in-memory history implementation.
|
||||
* Ideal for server rendering, tests, and non-DOM environments.
|
||||
* @link https://tanstack.com/router/latest/docs/framework/react/guide/history-types
|
||||
*/
|
||||
export declare function createMemoryHistory(opts?: {
|
||||
initialEntries: Array<string>;
|
||||
initialIndex?: number;
|
||||
}): RouterHistory;
|
||||
/** A fixed request location; server navigation is a no-op. */
|
||||
export declare function createServerHistory(href: string): RouterHistory;
|
||||
export declare function parseHref(href: string, state: ParsedHistoryState | undefined): HistoryLocation;
|
||||
export {};
|
||||
Reference in new issue
Block a user