zoukankan      html  css  js  c++  java
  • [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 '/'.

  • 相关阅读:
    vue项目中使用axios上传图片等文件
    es6入门set和map
    自定义组件实现双向数据绑定
    vue watch详细用法
    bind,call,applay的区别
    前端路由两种模式:hash、history
    jsonp封装成promise
    正则元字符理解2
    webpack配置
    vuex的几个细节
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6577579.html
Copyright © 2011-2022 走看看