使用精确而严格的道具

Ish*_*jaz 7 reactjs react-router react-router-dom

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

<Route>是一个内置组件,有两个不同的道具: exactstrict

问题

文件并没有明确的定义之间的差异exactstrict.

请帮助我.该文件非常令人困惑,当时还不清楚.

Bho*_*yar 21

用例1

如果你使用exactstrict在一起,然后location.pathname将只在路径道具提供完全匹配.

例:

<Route exact strict path="/one" component={About}/>
Run Code Online (Sandbox Code Playgroud)

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

例:

<Route exact strict path="/one/" component={About}/>
Run Code Online (Sandbox Code Playgroud)

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

用例2

如果仅使用strict,则location.pathname匹配具有尾部斜杠的匹配.

例:

<Route strict path="/one/" component={About}/>
Run Code Online (Sandbox Code Playgroud)

会匹配/one/,/one/two但不会/one.

用例3

如果仅使用exact,location.pathname则将匹配确切的位置路径.

例:

<Route exact path="/one" component={About}/>
Run Code Online (Sandbox Code Playgroud)

会匹配/one还是/one/.该exact道具不关心斜线.但它不会匹配/one/two.

  • 你以一种很好的方式提出答案.非常感谢. (2认同)