官术网_书友最值得收藏!

The strict prop

When the <Route> path has a trailing slash, and you would like to match this path, including the trailing slash, with the browser's URL, then include the strict prop. For example, after changing the <Route> path from '/dashboard' to '/dashboard/', the <Route> component would still match the URL path without the trailing slash. In other words, '/dashboard' would match the <Route> component with the '/dashboard/' path.

However, after adding the strict prop, React-Router ensures that <Route> matches only if the URL has a trailing slash:

<Route
path="/dashboard/"
component={DashboardComponent}
strict
/>

With this <Route> configuration in place, the '/dashboard' path would not match. However, when you add a trailing slash to the URL, as in '/dashboard/', the <Route> component with a strict prop will match and the DashboardComponent would be rendered.

Please note, if you mention additional URL segments, then it would still match the path prop mentioned in the <Route> component. For example, if the URL path is '/dashboard/123', it would match the  '/dashboard/' path with a  <Route> component that has the strict prop. To match a path including the additional URL segments, you can specify the exact prop along with the strict prop.
主站蜘蛛池模板: 万安县| 福建省| 桦南县| 江山市| 罗源县| 文安县| 新闻| 曲靖市| 陕西省| 左贡县| 吉隆县| 昆山市| 海淀区| 洛川县| 滁州市| 囊谦县| 双鸭山市| 高要市| 镶黄旗| 富宁县| 稷山县| 神木县| 宁河县| 大安市| 襄垣县| 衡阳县| 镇远县| 平泉县| 常州市| 阳信县| 庄浪县| 正镶白旗| 衡山县| 清镇市| 祥云县| 大埔区| 蒙自县| 宜章县| 申扎县| 诸城市| 长沙县|