[React Router v4] Use Regular Expressions with Routes

We can use regular expressions to more precisely define the paths to our routes in React Router v4.

 

To add regex for router, we only need to add (), inside (), we can write regex:

                <Route
                    path="/:date(\d{2}-\d{2}-\d{4}):ext(.[a-z]+)"
                    children={({match}) => {
                        const date = match.params.date;
                        const ext = match.params.ext;
                        return match && <h2>demo: {date}{ext}</h2>
                    }}></Route>

 

posted @ 2017-03-21 16:42  Zhentiw  阅读(349)  评论(0编辑  收藏  举报