<Route exact path={/^\/+$/g}>
<Redirect to="/home" />
</Route>
does work but:
Warning: Failed prop type: Invalid prop `path` supplied to `Route`.
Route@http://localhost:3000/static/js/vendors~main.chunk.js:789274:29
App@http://localhost:3000/static/js/main.chunk.js:666:79
Provider@http://localhost:3000/static/js/vendors~main.chunk.js:785880:15
Are we not supposed to pass a regex to path?
>Solution :
React-router-dom path props use path-to-rexexp. The path prop can be either a string or an array of strings.
If I’m not mistaken you are wanting to match and redirect from any path with one or more "/" repeated characters ("/", "//", "///", etc…). For this the path would be "/+". You can also specify the from prop on the Redirect component so there’s no need to be matched in a Route first if used inside a Switch.
<Redirect from="/+" to="/home" />
Note the Redirect to prop takes only a string.