Skip to content

Commit 78c643e

Browse files
docs: Add info about changes in matchPath() to upgrading/v5 guide (#8894)
* Add info about changes in matchPath() to upgrading v5 guide * Add signature
1 parent 110b924 commit 78c643e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

contributors.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@
6161
- underager
6262
- vijaypushkin
6363
- vikingviolinist
64+
- michal-antczak

docs/upgrading/v5.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,41 @@ To see the exact API of the new `useMatch` hook and its type declaration, check
891891

892892
<!-- TODO: Show examples for refactoring useRouteMatch -->
893893

894+
## Change the order of arguments passed to `matchPath`. Change pathPattern options.
895+
896+
Since version 6 the order of arguments passed to `matchPath` function has changed. Also pattern options has changed.
897+
898+
- first argument is pathPattern object, then comes pathname
899+
- pathPattern doesn't include `exact` and `strict` options any more. New `caseSensitive` and `end` options has been added.
900+
901+
Please refactor it as follows:
902+
903+
Before:
904+
```js
905+
// This is a React Router v5 app
906+
import { matchPath } from "react-router-dom";
907+
908+
const match = matchPath("/users/123", {
909+
path: "/users/:id",
910+
exact: true, // Optional, defaults to false
911+
strict: false // Optional, defaults to false
912+
});
913+
```
914+
915+
After:
916+
```js
917+
// This is a React Router v6 app
918+
import { matchPath } from "react-router-dom";
919+
920+
const match = matchPath({
921+
path: "/users/:id",
922+
caseSensitive: false, // Optional. Should be `true` if the static portions of the `path` should be matched in the same case.
923+
end: true // Optional. Should be `true` if this pattern should match the entire URL pathname
924+
}, "/users/123");
925+
```
926+
927+
928+
894929
## `<Prompt>` is not currently supported
895930

896931
`<Prompt>` from v5 (along with `usePrompt` and `useBlocker` from the v6 betas) are not included in the current released version of v6. We decided we'd rather ship with what we have than take even more time to nail down a feature that isn't fully baked. We will absolutely be working on adding this back in to v6 at some point in the near future, but not for our first stable release of 6.x.

0 commit comments

Comments
 (0)