mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
React router guard (#41333)
* Add types react-router-guard package * Add test for react-router-guard package * Export for Loadable react-loadable * Remove file react-router-guard-test.ts
This commit is contained in:
parent
bbeec088c3
commit
c794e7209b
47
types/react-router-guard/index.d.ts
vendored
Normal file
47
types/react-router-guard/index.d.ts
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
// Type definitions for react-router-guard 2.3
|
||||
// Project: https://github.com/laptransang/react-router-guard#readme
|
||||
// Definitions by: TSL <https://github.com/laptransang>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import * as React from 'react';
|
||||
import * as H from 'history';
|
||||
|
||||
export const history: H.History;
|
||||
|
||||
export {
|
||||
Loadable
|
||||
} from 'react-loadable';
|
||||
|
||||
export {
|
||||
BrowserRouter,
|
||||
Link,
|
||||
NavLink,
|
||||
Route,
|
||||
Router,
|
||||
Switch,
|
||||
} from 'react-router-dom';
|
||||
|
||||
export {
|
||||
Redirect,
|
||||
} from 'react-router';
|
||||
|
||||
export function lazy<T extends React.ComponentType<any>>(
|
||||
factory: () => Promise<{ default: T }>
|
||||
): React.LazyExoticComponent<T>;
|
||||
|
||||
export interface RouterGuardConfigProps {
|
||||
path: string;
|
||||
component: React.LazyExoticComponent<any>;
|
||||
canActivate?: Array<() => Promise<any>>;
|
||||
redirect?: string;
|
||||
exact?: boolean;
|
||||
routes?: RouterGuardConfigProps[];
|
||||
}
|
||||
|
||||
export interface RouterGuardProps {
|
||||
config: RouterGuardConfigProps[];
|
||||
history?: H.History;
|
||||
loading?: boolean | React.ReactElement;
|
||||
}
|
||||
|
||||
export class RouterGuard<T> extends React.Component<RouterGuardProps, any> {}
|
||||
12
types/react-router-guard/test/History.tsx
Normal file
12
types/react-router-guard/test/History.tsx
Normal file
@ -0,0 +1,12 @@
|
||||
import * as React from 'react';
|
||||
import { history } from 'react-router-guard';
|
||||
|
||||
const History = () => {
|
||||
React.useEffect(() => {
|
||||
history.push('/test');
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export default History;
|
||||
14
types/react-router-guard/test/Layout.tsx
Normal file
14
types/react-router-guard/test/Layout.tsx
Normal file
@ -0,0 +1,14 @@
|
||||
import * as React from 'react';
|
||||
|
||||
interface Props {
|
||||
children: any;
|
||||
}
|
||||
|
||||
const Layout = ({ children }: Props) => (
|
||||
<>
|
||||
<h1>Layout Test</h1>
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
|
||||
export default Layout;
|
||||
7
types/react-router-guard/test/Page.tsx
Normal file
7
types/react-router-guard/test/Page.tsx
Normal file
@ -0,0 +1,7 @@
|
||||
import * as React from 'react';
|
||||
|
||||
const Page = () => (
|
||||
<><h1>Page Test</h1></>
|
||||
);
|
||||
|
||||
export default Page;
|
||||
28
types/react-router-guard/test/RouterGuard.tsx
Normal file
28
types/react-router-guard/test/RouterGuard.tsx
Normal file
@ -0,0 +1,28 @@
|
||||
import * as React from 'react';
|
||||
import { RouterGuard, lazy, RouterGuardConfigProps } from 'react-router-guard';
|
||||
|
||||
import checkAuth from './checkAuth';
|
||||
|
||||
const config: RouterGuardConfigProps[] = [
|
||||
{
|
||||
path: '/',
|
||||
component: lazy(() => import('./Layout')),
|
||||
canActivate: [checkAuth],
|
||||
routes: [
|
||||
{
|
||||
path: '/test',
|
||||
component: lazy(() => import('./Page')),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const RouterGuardTest = () => (
|
||||
<>
|
||||
<RouterGuard
|
||||
config={config}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
export default RouterGuardTest;
|
||||
5
types/react-router-guard/test/checkAuth.ts
Normal file
5
types/react-router-guard/test/checkAuth.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export default function checkAuth(): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
28
types/react-router-guard/tsconfig.json
Normal file
28
types/react-router-guard/tsconfig.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"jsx": "react",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"test/RouterGuard.tsx",
|
||||
"test/Page.tsx",
|
||||
"test/Layout.tsx",
|
||||
"test/History.tsx"
|
||||
]
|
||||
}
|
||||
1
types/react-router-guard/tslint.json
Normal file
1
types/react-router-guard/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user