zoukankan      html  css  js  c++  java
  • vue-router和react-router-dom路由传参对照

    React
     
    1.动态路由传参
    <Route exact path="/detail/:id" component={Detail}/>
    接收
    componentDidMount() {
        console.log(this.props.match.params);
    }
    2.函数传参(push)加密的地址栏不可见
    <button onClick={() => this.props.history.push({ pathname: '/detail', state: { id: 3 } })}>通过函数跳转</button>
    接收
    componentDidMount() {
        //console.log(this.props.match.params);
        console.log(this.props.history.location.state);
    }
    不加密(query传参)
    this.props.router.push({ path : '/sort' ,query : { name: ' sunny'} })
    接收
    this.props.location.query.name
     
     
    以上方法都可以在 <Link  to={{path=:'/sort',query:{name:'xx'}}}>    传递
     
     
    Vue
     
    1.动态路由
    先在路由那配置
      {
         path: '/describe/:id',
         name: 'Describe',
         component: Describe
       }
     
    然后在组件中通过
          
     this.$router.push({
         path: `/describe/${id}`,
     })
    或者 <router-link  link="/describe/2" />
     
     
    接收
     
    this.$route.params.id
    2.通过 name和params配合
    先在路由配置 
     
    {
         path: '/describe',
         name: 'Describe',
         component: Describe
       } 
    

      

    然后在组件中通过
         
    this.$router.push({
              name: 'Describe',
              params: {
                id: id
              }
            })
    

      

    接收
    this.$route.params.id
    3.通过path和query配合使用
    先在路由配置   
    {
         path: '/describe',
         name: 'Describe',
         component: Describe
       }
    

      

     
    然后在组件中通过
        
     this.$router.push({
              path: '/describe',
              query: {
                id: id
              }
            })
    

      

    接收
    this.$route.query.id
  • 相关阅读:
    Word快捷键大全
    IT人物TOP100英雄人物榜
    关于简历的理解
    opengl头文件:错误: 无法打开包括文件:“gl/glut.h”: No such file or directory
    关于两次算法竞赛的心得
    MFC中关于将控件与成员变量绑定,实现用子类重载控件
    怎么入门
    正则表达式
    每天更新,督促自己学习
    测试人员的出路
  • 原文地址:https://www.cnblogs.com/zhangjixiang123/p/10128074.html
Copyright © 2011-2022 走看看