只要 URL 中有大写字母,React 路由器就会重定向
React router redirect whenever there is an uppercase in URL
我想解决每当 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 中是否至少有一个大写字母。
敏感道具应该可以解决这个问题,而不需要自定义渲染道具:
<Route
exact
strict
sensitive={false}
path='/:url([a-z/]*[A-Z]+[a-z/]*)/'
/>
我想解决每当 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 中是否至少有一个大写字母。
敏感道具应该可以解决这个问题,而不需要自定义渲染道具:
<Route
exact
strict
sensitive={false}
path='/:url([a-z/]*[A-Z]+[a-z/]*)/'
/>