[React Router v4] Use the React Router v4 Link Component for Navigation Between Routes

If you’ve created several Routes within your application, you will also want to be able to navigate between them. React Router supplies a Link component that you will use to make this happen.

Import Link:

import {
    BrowserRouter as Router,
    Route, Link
} from 'react-router-dom';

 

Add Nav section to the page

const Nav = () => (
  <nav>
      <Link to="/">Home</Link>
      <Link to="/about">About</Link>
      <Link replace to={{pathname: '/contact'}}>Contact</Link>
  </nav>
);

There are two ways to nav to another page.

 

1. to="/about"

2. to={{pathname: '/contact'}}

 

Here the 'replace' keyword able to help modify pushHistory. Once you use 'replace' it will replace previous state to current state, instead of add one state.

For example.

Current history: ['/', '/about', '/contact'], in the normal case, you hit the 'Back' button in your browser it will bring you back to '/about'.

But once you use 'replace', it will replace ['/', '/about'] to ['/', '/contact']. So you when hit 'Back' button , you will back to '/'.

posted @   Zhentiw  阅读(238)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2015-03-19 [Javascript] Drawing Styles on HTML5 Canvas
2015-03-19 [Javascript] Drawing Paths - Curves and Arcs
2015-03-19 [Javascript] Drawing Paths - Lines and Rectangles
2015-03-19 [Whole Web] [AngularJS + Grunt] Using ng-html2js to Convert Templates into JavaScript
2015-03-19 [TypeScript] 1. Catching JavaScript Mistakes with TypeScript
2015-03-19 [TypeScript] 0.First Example
点击右上角即可分享
微信分享提示