Invalid prop `path` of type `regexp` supplied to `Route`, expected `string`
See original GitHub issueVersion
PropTypes require String or [String] for Route, but Route allow use regex too.
Test Case
https://codesandbox.io/s/yv2z0x7qo1 (See route for topics).
Expected Behavior
No warnings. Allow types: String, RegExp, [String, RegExp]
Actual Behavior
Warning: Failed prop type: Invalid prop path of type regexp supplied to Route, expected string.
in Route
react-router-dom@4.3.1
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Invalid prop `path` of type `regexp` supplied to `Route ... - GitHub
Warning: Failed prop type: Invalid prop path of type regexp supplied to Route , expected string . in Route. react-router-dom@4.3.1.
Read more >Failed prop type: Invalid prop `path` supplied to `Route`
I'm providing a regular expression to a react-router Route like this: <Router> <Route path={/\/(?!path-to-exclude)/gi} component={Navbar}/> ...
Read more >reactjs/react-router - Gitter
Hello guys! What is wrong whne I get Warning: Failed prop type: Invalid prop 'component' of type 'object' supplied to 'Route', expected ...
Read more >react-router - UNPKG
+\n 'A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).'\n );\n } else {\n printWarning('Invalid argument supplied to...
Read more >Migrating to React Router v6: A complete guide
Migrate your React Router applications from v5 to v6 with this in-depth guide, including a review of additions and improvements from v5.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I think technically there is no problem to convert RegExp to strings on react-router level, so that it will behave pretty the same as now. Even concatenating is ok, since even now there is kind of support RegExp in stings with custom match parameters, and it will be the same issue either with text with RegExp or real RegExp. So it should be up to developer not to shoot into his own leg with that concatenations.
Still my point is if react-router uses path-to-regexp, it should support all of it’s features.
But for what it’s really needed to be supported as RegExp by react-router is because of this issue in pillarjs/path-to-regexp#99. And for now there is no other way to use
(?!something)than using it as RegExp@pshrmn, thank you for the clarification. OK.