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>

[React Router v4] Use URL Parameters的更多相关文章

  1. [React Router v4] Parse Query Parameters

    React Router v4 ignores query parameters entirely. That means that it is up to you to parse them so ...

  2. [Web 前端] React Router v4 入坑指南

    cp from : https://www.jianshu.com/p/6a45e2dfc9d9 万恶的根源 距离React Router v4 正式发布也已经过去三个月了,这周把一个React的架子 ...

  3. [React Router v4] Conditionally Render a Route with the Switch Component

    We often want to render a Route conditionally within our application. In React Router v4, the Route ...

  4. React Router V4发布

    React Router V4 正式版发布,该版本相较于前面三个版本有根本性变化,遵循 Just Component 的 API 设计理念. 本次升级的主要变更有: 声明式 Declarative 可 ...

  5. [React Router v4] Intercept Route Changes

    If a user has entered some input, or the current Route is in a “dirty” state and we want to confirm ...

  6. [React Router v4] Redirect to Another Page

    Overriding a browser's current location without breaking the back button or causing an infinite redi ...

  7. [React Router v4] Render Multiple Components for the Same Route

    React Router v4 allows us to render Routes as components wherever we like in our components. This ca ...

  8. [React Router v4] Render Catch-All Routes with the Switch Component

    There are many cases where we will need a catch-all route in our web applications. This can include ...

  9. [React Router v4] Render Nested Routes

    With React Router v4 the entire library is built as a series of React components. That means that cr ...

随机推荐

  1. 一次Linux磁盘损坏导致系统不可用恢复实例

    Linux操作系统的server重新启动后.系统启动报错,系统无法正常使用. 1.报错信息 1.1.报错屏幕信息 1.2.报错信息提取关键信息 (1)/dev/sda3:File -(inode #1 ...

  2. [Python] The get() method on Python dicts and its "default" arg

    # The get() method on dicts # and its "default" argument name_for_userid = { 382: "Al ...

  3. Python 极简教程(六)运算符

    运算符,我们日常生活中使用的加减乘除,都是运算符的一种.当然这种一般我们称为算术运算符,用于处理数字运算的. 但是在计算机语言中,还有很多的运算符.用于处理不用的情况. 主要有以下几类: 算术运算符 ...

  4. Appium_Java运行测试脚本时问题汇总

    问题一.java.lang.NoClassDefFoundError: org/openqa/selenium/remote/SessionNotFoundExceptionCaused by: ja ...

  5. 编程——C语言的问题,堆栈

    堆和栈的区别一.预备知识—程序的内存分配一个由c/C++编译的程序占用的内存分为以下几个部分 1.栈区(stack)— 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等.其操作方式类似于数据结 ...

  6. PB导出数据excel格式dw2xls

    PB导出数据excel格式dw2xls 使用DW2XLS控件 语法 uf_save_dw_as_excel ( dw, filename ) 參数 dw A reference to the data ...

  7. 10.8 android输入系统_实战_使用GlobalKey一键启动程序

    11. 实战_使用GlobalKey一键启动程序参考文章:Android 两种注册(动态注册和静态注册).发送广播的区别http://www.jianshu.com/p/ea5e233d9f43 [A ...

  8. 算法 Tricks(四)—— 判断序列中的字符/数值是否交替出现

    比如:353, 54545,数字都是交替出现的: bool alternate = true; for (int i = 0; i < M.size(); ++i){ if (M[i] != M ...

  9. 分析Net 内存对象

    .Net 内存对象分析   在生产环境中,通过运行日志我们会发现一些异常问题,此时,我们不能直接拿VS远程到服务器上调试,同时日志输出的信息无法百分百反映内存中对象的状态,比如说我们想查看进程中所有的 ...

  10. 利用VS安装项目打包软件的做法

    作者:朱金灿 来源:http://blog.csdn.net/clever101 昨天摸索了一下,发现使用VS安装项目来打包软件还是挺方便的. 1. 创建一个安装项目工程,如下图: 2. 设置工程属性 ...