Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add routeParams to useMatch #9793

Merged
merged 7 commits into from
Jan 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add another example to the docs
  • Loading branch information
Tobbe committed Jan 3, 2024
commit ff08d1eb82f690917942cd5bfc2fcd37eace8566
19 changes: 19 additions & 0 deletions docs/docs/router.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,25 @@ The above example will match /product/shirts/213, but not /product/pants/213
To get the path you need to pass to `useMatch` you can use
[`useRoutePaths`](#useroutepaths) or [`useRoutePath`](#useroutepath)

Here's an example:

```jsx
<Route path="/{animal}/{name}" page={AnimalPage} name="animal" />

const animalRoutePath = useRoutePath('animal')
// => '/{animal}/{name}'

const matchOnlyDog = useMatch(animalRoutePath, { routeParams: { animal: 'dog' }})
const matchFullyDynamic = useMatch(animalRoutePath)
```

In the above example, if the current page url was
`https://example.org/dog/fido` then both `matchOnlyDog` and `matchFullyDynamic`
would have `match: true`.

If the current page instead was `https://example.org/cat/garfield` then only
`matchFullyDynamic` would match

See below for more info on route parameters.

## Route parameters
Expand Down
Loading