preface

Each time you configure the React Route, consider whether you should add exact or strict to the

component. The following girls will be in the way they think more clear to list what scenes need to add and not add.

The react-router V4 + version is the first version of the react-router v4+ version. The v5 version is the first version of the react-router v4+ version. The V5 version is the first version of the react-router V4 + version

exact

The default value is false. If exact is set to true, the routes can be matched only when they are the same as the routes. However, the routes can be matched only when the routes have a slash. If exact is added to the parent route, the child route cannot be matched. You are advised to add exact to the child route, as shown in the following

/ / parent routing
<Switch>
    <Route path="/a" component={ComponentA} />
</Switch>
Copy the code
// subroute, tuanDetail component
<Switch>
        <Route path="/a/b" exact component={ComponentB}/>
</Switch>
Copy the code

strict

Strict defaults to False. If true, the route has a slash but the URL does not have a slash, which does not match

case

conclusion

If there is no subroute, it is recommended that you add an exact match. If there are child routes, you are advised to add exact to the child route but not to the parent route. Strict specifies whether there is a slash. Therefore, you can ignore this parameter.

Other links

The original address: raoenhui. Making. IO/react / 2019 /… Reacttraining.com/react-route… Reacttraining.com/blog/react-…

Happy coding .. 🙂