Merge pull request #28883 from gillchristian/master

Update definitions for react-router/v3
This commit is contained in:
Jesse Trinity
2018-09-17 10:52:31 -07:00
committed by GitHub
3 changed files with 21 additions and 0 deletions
+1
View File
@@ -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
View File
@@ -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;