React Router v4 ignores query parameters entirely. That means that it is up to you to parse them so that you can use that additional information as required. There are several strategies for doing this that we will look at.

There are tow ways to pass query params in path:

      <NavLink to="/query?id=123">Demo123</NavLink>
<NavLink to={{pathname: '/query', search: 'id=456'}}>Demo456</NavLink>

First is append ?id=123 to the end of path.

Second is using 'search' prop.

React Router no longer help to parse query parameters for us, we can use new web api 'URLSearchParams':

                <Route path="/query" render={({match, location}) => {
return (
<div>
<pre>
{JSON.stringify(match, null, 2)}
</pre>
<pre>
{JSON.stringify(location, null, 2)}
</pre>
<h1>Search id: {new URLSearchParams(location.search).get('id')}</h1>
<h2>new URLSearchParams(location.search).get('id')</h2>
</div>
)
}}></Route>

[React Router v4] Parse Query Parameters的更多相关文章

  1. [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 ...

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

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

  3. React Router V4发布

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

  4. [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 ...

  5. [React Router v4] Redirect to Another Page

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

  6. [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 ...

  7. [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 ...

  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. 12、python单步调试工具pdb

    pdb 第4种方式是启动Python的调试器pdb,让程序以单步方式运行,可以随时查看运行状态.我们先准备好程序: # err.py s = '0' n = int(s) print(10 / n) ...

  2. Mongodb总结1-启动和Shell脚本

    2013年,还在秒针,当时听说了Mongodb,就学习了下,搞了下HelloWorld.主要是熟悉Mongodb的启动.命令行的Shell脚本.Java访问的CRUD. 今天,由于需要,再次回顾和进一 ...

  3. Redfield Water Ripples 2.02(水波滤镜中文绿色版-支持CC)

    Redfield Water Ripples 能够用于设计具有高度现实主义风格的水波纹特效,它提供了诸多属性选项,其 3D 渲染品质另人映像深刻.此滤镜很易用,其随机设定生成器可创建差点儿无限的水波纹 ...

  4. 编程一一C语言问题,指针函数与函数指针

    资料来源于网上: 一.指针函数:指返回值是指针的函数      类型标识符    *函数名(参数表)       int *f(x,y); 首先它是一个函数,只不过这个函数的返回值是一个地址值.函数返 ...

  5. (转)Could not execute auto check for display colors using command /usr/bin/xdpyinfo. Check if the DISPL

    转自:http://blog.csdn.net/huashnag/article/details/9357517 Starting Oracle Universal Installer... Chec ...

  6. BAT面试常的问题和最佳答案

    原标题:BAT面试常的问题和最佳答案 技术面试 1.servlet执行流程 客户端发出http请求,web服务器将请求转发到servlet容器,servlet容器解析url并根据web.xml找到相对 ...

  7. gvim不能直接打开360压缩打开的文件

    1. 压缩文件a.rar 2. 默认使用360压缩打开 3.用gvim打开对应的a.c文件,提示permission denied 4.用gvim跟踪目录,发现360管理的缓冲目录无法打开 原因未分析 ...

  8. js课程 4-11 表格如何实现隔行换色

    js课程 4-11 表格如何实现隔行换色 一.总结 一句话总结:表格奇数行和偶数行判断,赋予不同的样式. 1.表格如何隔行换色? 表格奇数行和偶数行判断,赋予不同的样式. 21 <script& ...

  9. UVA 11461 - Square Numbers 数学水题

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  10. 源码笔记---MBProgressHUD

    前言 作为初学者,想要快速提高自己的水平,阅读一些优秀的第三方源代码是一个非常好的途径.通过看别人的代码,可以学习不一样的编程思路,了解一些没有接触过的类和方法. MBProgressHUD是一个非常 ...