使用精确和严格的道具 [英] Usage of exact and strict props

查看:37
本文介绍了使用精确和严格的道具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 React-JS 中使用 React-Router:

I am working with React-Router in React-JS:

是一个内置组件,有两个不同的 props:exactstrict

The <Route> is an built in component and have two different props: exact and strict

问题

文档 没有明确定义两者之间的差异exactstrict .

The documentation does not clearly defines the differences in between the exact and strict .

请帮助我.该文件非常混乱,在这一点上不清楚.

Kindly help me. The document is very confusing and not clear at that point.

推荐答案

用例 1

如果您同时使用 exactstrict,那么 location.pathname 只会与路径道具中提供的完全匹配.

Use case 1

If you use exact and strict together, then the location.pathname will only match exactly as provided in path props.

示例:

<Route exact strict path="/one" component={About}/>

只会匹配 /one 而不会匹配 /one//one/two.

Will only match /one but not /one/ and /one/two.

示例:

<Route exact strict path="/one/" component={About}/>

只会匹配 /one/ 而不会匹配 /one/one/two.

Will only match /one/ but not /one and /one/two.

如果您只使用 strict,则 location.pathname 将匹配尾随斜杠.

If you use only strict, then the location.pathname will match which have trailing slash.

示例:

<Route strict path="/one/" component={About}/>

将匹配 /one//one/two 但不匹配 /one.

Will match /one/ and /one/two but not /one.

如果您只使用 exact,那么 location.pathname 将匹配精确的位置路径.

If you use only exact, then the location.pathname will match exact location path.

示例:

<Route exact path="/one" component={About}/>

将匹配 /one/one/.exact 道具不关心尾部斜杠.但它不会匹配/one/two.

Will match /one or /one/. The exact props doesn't care for trailing slash. But it will not match /one/two.

这篇关于使用精确和严格的道具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆