Fix @reach/router .useMatch types. Path params are added to the return object. (#43248)

This commit is contained in:
Oliver Jackman
2020-03-20 11:20:37 -04:00
committed by GitHub
parent ff8cb219da
commit e223e44833
2 changed files with 12 additions and 2 deletions
+2 -1
View File
@@ -4,6 +4,7 @@
// A.Mokhtar <https://github.com/xMokAx>,
// Awwit <https://github.com/awwit>
// wroughtec <https://github.com/wroughtec>
// O.Jackman <https://github.com/chilledoj>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
@@ -161,4 +162,4 @@ export function useNavigate(): NavigateFn;
export function useParams(): any;
export function useMatch(pathname: string): null | { uri: string; path: string };
export function useMatch(pathname: string): null | { uri: string; path: string, [param: string]: string };
+10 -1
View File
@@ -7,7 +7,8 @@ import {
LocationProvider,
RouteComponentProps,
Router,
Redirect
Redirect,
useMatch
} from '@reach/router';
interface DashParams {
@@ -22,6 +23,13 @@ const Dash = (props: RouteComponentProps<DashParams>) => (
const NotFound = (props: RouteComponentProps) => <div>Route not found</div>;
const UseMatchCheck = (props: RouteComponentProps) => {
const match = useMatch('/params/:one');
return (
<div>{match ? match.one : 'NO PATH PARAM' }</div>
);
};
render(
<Router className="my-class">
<Router component="div">
@@ -32,6 +40,7 @@ render(
</Router>
<Home path="/" />
<Dash path="/default/:id" />
<UseMatchCheck path="/params/*" />
<NotFound default />
<Link to="/somepath" rel="noopener noreferrer" target="_blank" />