Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Router v4 - Redirect to all lowercase URL?

I'm trying to figure out if it's possible to detect URLs with capital letters and redirect them to the same URL with all lowercase letters.

So, something like '/products/Top/' would be redirected to '/products/top/'.

Is something like this possible with react-router-dom in React Router v4?

like image 473
Bill Bergquist Avatar asked Oct 23 '25 04:10

Bill Bergquist


1 Answers

Figured it out:

<Route sensitive 
       path="/:slug1*:slug2([A-Z]):slug3*/"
       render={props => <Redirect to={`${props.location.pathname.toLowerCase()}`}/>}/>
like image 86
Bill Bergquist Avatar answered Oct 25 '25 19:10

Bill Bergquist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!