[React Router v4] Redirect to Another Page
Overriding a browser's current location without breaking the back button or causing an infinite redirect can be tricky sometimes. In this lesson we'll learn how React Router v4 allows us to easily achieve a redirect without getting bogged down in browser history.
import React from 'react';
import { Link, Route, Redirect } from 'react-router-dom'; const Menu = () => (
<div>
<h1>Menu</h1>
<Link to="/menu/food">Food</Link>
<Link to="/menu/drinks">Drinks</Link>
<Link to="/menu/123">Redirect</Link> <Route path="/menu/:section([a-z]+)" render={({ match }) => {
return <h3>Section: {match.params.section}</h3>
}}>
</Route>
<Route path="/menu/:section(\d+)" render={({ match }) => {
return <Redirect to="/menu/food"></Redirect>
}}></Route>
</div>
); export default Menu;
So if we hit /menu/food or /menu/drink, we will go to:
<Route path="/menu/:section([a-z]+)" render={({ match }) => {
return <h3>Section: {match.params.section}</h3>
}}>
Becase :section([a-z]+) match 'food' or 'drink'.
If we hit /menu/123, we will go to:
<Route path="/menu/:section(\d+)" render={({ match }) => {
return <Redirect to="/menu/food"></Redirect>
}}></Route>
It will render Redirect component, and redirect us to /menu/food
[React Router v4] Redirect to Another Page的更多相关文章
- [Web 前端] React Router v4 入坑指南
cp from : https://www.jianshu.com/p/6a45e2dfc9d9 万恶的根源 距离React Router v4 正式发布也已经过去三个月了,这周把一个React的架子 ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- React Router V4发布
React Router V4 正式版发布,该版本相较于前面三个版本有根本性变化,遵循 Just Component 的 API 设计理念. 本次升级的主要变更有: 声明式 Declarative 可 ...
- [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 ...
- [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 ...
随机推荐
- windows7下安装Office2010提示需要安装MSXML6.10.1129
平台:Windows 7 问题:刚刚下载的ghost Win 7,安装过程一切顺利,进入系统后把集成的软件全部卸载,清理完垃圾,安装了VC库,在安装Office2010时提示需要安装MSXML6.10 ...
- Qt 图片浏览器 实现图片的放大缩小翻转等功能
图片的功能 源码: wiget.h #ifndef WIDGET_H #define WIDGET_H #include <QPixmap> #include <QImage> ...
- Excel查询序列所相应的值-vLoopup函数,求比例分子改变但分母不变
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveWV3ZWlvdXlhbmc=/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- HTML基础第十一讲---背景标志
转自:https://i.cnblogs.com/posts?categoryid=1121494 您是否老觉得网页「空空的」,没错!一个可能是我们还没有很多内容,另一个可能则是我们还没有设定网页背景 ...
- 12.SpringBoot+MyBatis(XML)+Druid
转自:https://www.cnblogs.com/MaxElephant/p/8108342.html 主要是在Spring Boot中集成MyBatis,可以选用基于注解的方式,也可以选择xml ...
- oled的一套stm32实验2(自己的实验)
stm32与OLED屏接口的引脚介绍: CS————GPIOD3: RST————GPIOD4: DC—————GPIOD5: D0——————GPIOD6: D1——————GPIOD7; 上是我参 ...
- JS学习笔记 - fgm练习 2-11- 改变图片路径 var img = new Image(); 图片预加载
<style> *{ margin: 0;padding: 0; list-style: none; } body{ background: black; } .outer{ margin ...
- sql语句的编程手册 SQL PLUS
一.SQL PLUS 引言 SQL命令 以下17个是作为语句开头的关键字: alter drop revoke audit grant rollback* commit* insert select ...
- C# 获取文件路径,读取项目中某程序集下文件
获取文件路径 ------------------------------------------------------------------------- winform获取文件路径: stri ...
- javascript进阶教程第三章--匿名和闭包--案例实战
javascript进阶教程第三章--匿名和闭包--案例实战 一.学习任务 通过几个小练习回顾学过的知识点 二.实例 练习1: 实例描述:打开页面后规定时间内弹出一个新窗口,新窗口指定时间后自动关闭. ...