zoukankan      html  css  js  c++  java
  • Link & Redirect

    Link

      Link标签,用于实现React-Router功能的跳转。(意思是就不要使用a标签了)

      1)to:string,指明要跳转的path。

    import { Link } from 'react-router-dom'
    
    <Link to="/about">About</Link>

      2)Link的牛逼之处,就是可以拼完整url。

      to:object,指明要跳转的path、query、state。

    <Link to={{
      pathname: '/courses',
      search: '?sort=name',
      hash: '#the-hash',
      state: { fromDashboard: true }
    }}/>

      3)replace,When true, clicking the link will replace the current entry in the history stack instead of adding a new one.

    <Link to="/courses" replace />

     【Redirect

      Redict会直接跳转到新地址。

    import { Route, Redirect } from 'react-router'
    
    <Route exact path="/" render={() => (
      loggedIn ? (
        <Redirect to="/dashboard"/>
      ) : (
        <PublicHomePage/>
      )
    )}/>

    参考:https://reacttraining.com/react-router/web/guides/quick-start

  • 相关阅读:
    channel分析
    Nginx|基础
    item2
    搜索引擎技巧
    计算机网络|概述
    操作系统|进程
    分布式事务一致性
    画图工具StartUML
    内存分配
    MPG分析
  • 原文地址:https://www.cnblogs.com/tekkaman/p/6992064.html
Copyright © 2011-2022 走看看