react-history-switch
Version:
Self-hosted context-free Switch routing component for History.js library (React). The library was created to transfer navigation responsibility from a view into Mobx state container (MVC). Also can be used separately as a self-hosted router
23 lines (22 loc) • 1.01 kB
TypeScript
import { BrowserHistory, HashHistory, MemoryHistory } from 'history';
import React from 'react';
export interface ISwitchItem {
path: string;
element?: React.ComponentType<any>;
guard?: () => boolean | Promise<boolean>;
prefetch?: (params: Record<string, any>) => Record<string, any> | Promise<Record<string, any>>;
unload?: (params: Record<string, any>) => Promise<void> | void;
redirect?: string | ((params: Record<string, any>) => string | null);
}
export interface ISwitchProps {
items: ISwitchItem[];
history?: BrowserHistory | MemoryHistory | HashHistory;
Forbidden?: React.ComponentType<any>;
NotFound?: React.ComponentType<any>;
Loader?: React.ComponentType<any>;
Error?: React.ComponentType<any>;
onLoadStart?: () => void;
onLoadEnd?: (isOk?: boolean) => void;
}
export declare const Switch: ({ Loader, Forbidden, NotFound, Error, history, items, onLoadStart, onLoadEnd, }: ISwitchProps) => JSX.Element;
export default Switch;