Attempted import error: 'useRouterMatch' is not exported from 'react-router-dom'

Viewed 1795

I have copied the react router "2nd Example: Nested Routing" example from the react-router docs in to my app as-is. (The "1st Example: Basic Routing" works fine)

The error I'm getting is Attempted import error: 'useRouterMatch' is not exported from 'react-router-dom'

The example references useRouterMatch but it doesn't seem to be exported and searching google for 'useRouterMatch' returns no results outside of the example so I'm having a hard time finding docs or anything.

Here are all my react-router dependencies from package.json:

    "@types/react-router": "^5.1.1",
    "@types/react-router-bootstrap": "^0.24.5",
    "@types/react-router-dom": "^4.3.5",
    "react-router-bootstrap": "^0.24.4",
    "react-router-dom": "^5.1.2",
1 Answers

Turns out there were a couple of issues here.

First, there seems to be a typo in the docs (which I've submitted a PR for)

Second, I probably should have mentioned I'm using Typescript, and after reading a couple of threads, I realized that while I had the latest react-router-dom package, I didn't have the latest types. Updating that package and changing useRouterMatch to useRouteMatch seems to have fixed the problem.

Related