Home > Blockchain >  How can I match if the current route matches a pattern in React Router Dom v6?
How can I match if the current route matches a pattern in React Router Dom v6?

Time:04-08

I've got:

export const ACCOUNT_PORTAL_PATHS = [
      'home/*',
      'my-care/*',
      'chats/*',
      'profile/*',
      'programs/*',
      'completion/*',
    ]

If the current path is any of those, I want to know. I managed to get the current path with:

const { search: searchParams, pathname } = useLocation();

and that yields, in this example:

pathname: "/my-care/1234"

What's the best way to match?

Thanks in advance!

CodePudding user response:

If you just want to know if you are on a matching path, you can use the Edit epic-shtern-gyuolz

  • Related