mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
Update definitions for react-router/v3
This commit is contained in:
Vendored
+1
@@ -10,6 +10,7 @@
|
||||
// Karol Janyst <https://github.com/LKay>
|
||||
// Dovydas Navickas <https://github.com/DovydasNavickas>
|
||||
// Ross Allen <https://github.com/ssorallen>
|
||||
// Christian Gill <https://github.com/gillchristian>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
|
||||
+9
@@ -1,3 +1,12 @@
|
||||
import { RoutePattern } from "react-router";
|
||||
|
||||
export function formatPattern(pattern: RoutePattern, params: any): string;
|
||||
|
||||
export function matchPattern(
|
||||
pattern: string,
|
||||
pathname: string
|
||||
): {
|
||||
remainingPathname: string;
|
||||
paramNames: string[];
|
||||
paramValues: string[];
|
||||
} | null;
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
RouteComponentProps,
|
||||
WithRouterProps
|
||||
} from "react-router";
|
||||
import { matchPattern } from 'react-router/lib/PatternUtils';
|
||||
import { createHistory, History } from "history";
|
||||
|
||||
const routerHistory = useRouterHistory(createHistory)({ basename: "/test" });
|
||||
@@ -181,3 +182,13 @@ ReactDOM.render((
|
||||
>
|
||||
</Router>
|
||||
), document.body);
|
||||
|
||||
const matchedPattern = matchPattern("/foo", "/foo/bar");
|
||||
|
||||
if (matchedPattern) {
|
||||
matchedPattern.remainingPathname === "/bar";
|
||||
matchedPattern.paramNames.forEach(name => {});
|
||||
matchedPattern.paramValues.forEach(value => {});
|
||||
}
|
||||
|
||||
matchPattern("/foo", "/baz") === null;
|
||||
|
||||
Reference in New Issue
Block a user