我想解析URL中的任何一个大写字母,它都需要重定向到小写的URL。
我在寻找正确的正则表达式的路径部分遇到一些问题。
正则表达式/:url2 *([A-Z])/仅在所有字母均为大写时才起作用,而在这种情况下/ home / Support /不起作用
[我在这里尝试了不同的路径https://pshrmn.github.io/route-tester,但没有任何运气。
这是我的代码
<Route
exact
strict
sensitive
path='/:url2*([A-Z])/'
render={props => {
const path = props.location.pathname
return <Redirect to={`${path.toLowerCase()}`} />
}}
/>
我不是专家,但请问这是否对您有用。
<Route
exact
strict
sensitive
path='/:url([a-z/]*[A-Z]+[a-z/]*)/'
render={props => {
const path = props.location.pathname
return <Redirect to={`${path.toLowerCase()}`} />
}}
/>
正则表达式/:url([a-z/]*[A-Z]+[a-z/]*)/
检查URL中是否至少有一个大写字母。