在react中使用Link帶參數的路由跳轉


1,引入Link模塊

 import { NavLink as Link } from 'react-router-dom'

2,Link標簽中帶上要傳遞的參數

<Link to={
        {
          pathname:`/要跳轉的路徑`,
          state:{key值:val值}
        }
      }>

3,在跳轉頁面接收傳遞的參數

componentWillMount(){
    //console.log(this.props.location)//傳遞過來的所有參數
    console.log(this.props.location.state.key值)//val值
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM