React Router: Cannot read property ‘pathname’ of undefined

I got the above error message and it was extremely cryptic. I tried the other solutions mentioned and it didn’t work.

Turns out I accidentally forgot to include the to prop in one of the <Link /> components.

Even if the <Link /> does not require a to prop, you simply just add and write it with empty quotes -> e.g. <Link to="" />. That will do the trick!

Wish the error message was clearer. A simple required prop "to" not found or something similar would have been helpful. Hopefully, this saves someone else who has encountered the same problem some time.

Leave a Comment