zoukankan      html  css  js  c++  java
  • [React Router v4] Use URL Parameters

    URLs can be looked at as the gateway to our data, and carry a lot of information that we want to use as context so that the user can return to a particular resource or application state. One way to achieve this is through the use of URL parameters that include important data right in the URL of the route that gets matched in React Router v4.

    <NavLink to="/demo" activeClassName={'active'}>Demo</NavLink>

    Match:

                    <Route
                        path="/:page"
                        children={({match}) => {
                            console.log("match:", match)
                            const page = match.params.page;
                            return match && <h2>demo: {page} </h2>
                        }}></Route>
    <NavLink to="/demo/react" activeClassName={'active'}>Demo</NavLink>

    Match:

                    <Route
                        path="/:page/:sub"
                        children={({match}) => {
                            const page = match.params.page;
                            const sub = match.params.sub;
                            return match && <h2>demo: {page} -- {sub}</h2>
                        }}></Route>
    <NavLink to="/demo-react" activeClassName={'active'}>Demo</NavLink>

    Match:

                    <Route
                        path="/:page-:sub"
                        children={({match}) => {
                            const page = match.params.page;
                            const sub = match.params.sub;
                            return match && <h2>demo: {page} -- {sub}</h2>
                        }}></Route>
  • 相关阅读:
    异常方法测试实验
    exception测试实验(研究finally的作用)
    idea中文注释出现乱码,我靠自己解决了
    按装parallels tool的失败之路
    实验七
    实验六
    实验五
    实验四
    实验3
    html转义字符图
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6595103.html
Copyright © 2011-2022 走看看