Merge pull request #21670 from pasieronen/react-router-prompt

react-router/react-router-dom: fix typing for getUserConfirmation and Prompt props
This commit is contained in:
Benjamin Lichtman
2017-11-21 10:54:31 -08:00
committed by GitHub
3 changed files with 10 additions and 5 deletions
+2 -2
View File
@@ -27,7 +27,7 @@ export {
export interface BrowserRouterProps {
basename?: string;
getUserConfirmation?(): void;
getUserConfirmation?: ((message: string, callback: (ok: boolean) => void) => void);
forceRefresh?: boolean;
keyLength?: number;
}
@@ -35,7 +35,7 @@ export class BrowserRouter extends React.Component<BrowserRouterProps, any> {}
export interface HashRouterProps {
basename?: string;
getUserConfirmation?(): void;
getUserConfirmation?: ((message: string, callback: (ok: boolean) => void) => void);
hashType?: 'slash' | 'noslash' | 'hashbang';
}
export class HashRouter extends React.Component<HashRouterProps, any> {}
+2 -2
View File
@@ -34,14 +34,14 @@ export interface RouterChildContext<P> {
export interface MemoryRouterProps {
initialEntries?: H.LocationDescriptor[];
initialIndex?: number;
getUserConfirmation?: (() => void);
getUserConfirmation?: ((message: string, callback: (ok: boolean) => void) => void);
keyLength?: number;
}
export class MemoryRouter extends React.Component<MemoryRouterProps, any> { }
export interface PromptProps {
message: string | ((location: H.Location) => void);
message: string | ((location: H.Location) => string | boolean);
when?: boolean;
}
export class Prompt extends React.Component<PromptProps, any> { }
+6 -1
View File
@@ -12,8 +12,13 @@ const initialRouterEntries = [
}
];
const getConfirmation = (message: string, callback: (ok: boolean) => void): void => {
const allowTransition = window.confirm(message);
callback(allowTransition);
};
const MemoryRouterExample = () => (
<MemoryRouter initialEntries={initialRouterEntries} initialIndex={1}>
<MemoryRouter initialEntries={initialRouterEntries} initialIndex={1} getUserConfirmation={getConfirmation}>
<div>
<ul>
<li><Link to="/">Home</Link></li>