From c77ebee0fec7fc98dd6ca21210816512912e3f63 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Wed, 3 Jan 2024 13:04:29 +0100 Subject: [PATCH] Add routeParams to useMatch (#9793) Make it possible to specify route param values that need to match. If this is your route: `` And you want to only match posts from 2001 you can now do this: `useMatch('/blog/{year}/{month}/{day}', { routeParams: { year: '2001' } })` This is **finally** a solution to matching route paths. The work started in #7469, but we were never able to come up with an api/dx that we really liked. This PR and #9755 together however provides a solution that we're much more happy with, and that also supports the use case outlined in that original PR. Here's the example from #7469 as it could be solved with the code in this PR ```jsx const Navbar () => { const { project } = useParams() const routePaths = useRoutePaths() const modes = [ { name: "Info", route: routes.info({ project }), match: useMatch(routePaths.info), // using the hook together with routePaths }, { name: "Compare", route: routes.compare({ project, id: "1" }), match: useMatch(useRoutePath('compare')), // alternative to the above }, // ... ] return ( <> {modes.map((x) =>