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

原文地址:https://www.cnblogs.com/zhangjixiang123/p/10128074.html

时间: 2024-07-31 03:21:50

vue-router和react-router-dom路由传参对照的相关文章

50.React跳转路由传参3种方法和区别

1.路由表配置:参数地址栏显示 <Route path="/list/:id" component={List} />html:<Link to='/list/2' >跳转列表页面</Link>Js: this.props.history.push('/list/2');List页面接收: console.log(this.props.match.params.id)//传递过来的所有参数 2.query方法:参数地址栏不显示,刷新地址栏,参数丢失h

Vue路由传参及传参后刷新导致参数消失处理

参考:https://blog.csdn.net/qq_43103581/article/details/82260073(vue 路由传递参数,刷新页面后参数丢失) 项目功能需要,要从列表页跳转到第三方提供的URL上(这里第三方页面我是通过iframe引入在详情页,目的是点击返回时可以通过keepAlive让列表页不刷新,如果不通过iframe直接跳第三方链接,那么返回必然会重新拉取数据),一路百度,刚开始使用 this.$router.push({name:'list', params:{i

Vue路由传参的几种方式

原 Vue路由传参的几种方式 2018年07月28日 23:52:40 广积粮缓称王 阅读数 12613 前言:顾名思义,vue路由传参是指嵌套路由时父路由向子路由传递参数,否则操作无效.传参方式可以划分为params传参和query传参,params传参又可以分为url中显示参数和不显示参数两种方式.具体区分和使用后续分析. 参考官网:https://router.vuejs.org/zh/guide/essentials/navigation.html params传参(url中显示参数)

vue路由传参

vue路由url 传参 :params 从客户列表页 通过路由跳转到客户详情页 查看客户详情时 需要将当前客户的id 和所属企业的id 当做参数传给后台. 在跳转时,将客户id 和企业id 通过路由传参 传给 客户详情页 客户列表: 客户详情 通过 this.$router.params 获取 参数 路由 router.js 路由传一个对象:query 有时我们需要传很多数据过去,为了避免大量拼接,我们可以传一个对象 通过this.$router.query接收对象参数 这里router 路由

前端Vue框架 04 路由:逻辑跳转、路由传参 项目组件的数据局部化处理data(){ return{} } 组件的声明周期 组件间通信 各种第三方插件(vuex,axios,element-ui,(jq+bs))

项目初始化 """ 1)根组件:App.vue <template> <div id="app"> <router-view /> </div> </template> 2)路由配置:router/index.js const routes = [ { path: '/', name: 'Home', component: Home } ]; 3)组件:views和components文件夹 i)

第十篇:Vue路由传参

路由传参 用于组件与组件之间通过路由传递数据 通过url正则传递数据 i)设置 路由: path: '/goods/detail/:pk' | '/goods/:pk/detail/:xyz' 请求: '/goods/detail/任意字符' | '/goods/任意字符/detail/任意字符' ii)如何传 <router-link :to="`/goods/detail/${pk}`"></router-link> this.$router.push(`/

vue路由传参页面刷新参数丢失问题解决方案

最近项目中涉及到跨页面传参数和后台进行数据交互,看到需求之后第一反应就是用路由传参来解决:Vue中给我们提供了三种路由传参方式,下面我们一个一个的来看一下: 方法一:params传参: this.$router.push({ name:"admin", //这里的params是一个对象,id是属性名,item.id是值(可以从当前组件或者Vue实例上直接取) params:{id:item.id} }) //这个组件对应的路由配置 { //组件路径 path: '/admin', //

vue路由传参问题

路由传参 带参的方式 第一种方式 通过 params 带参 刷新页面消失 this.$router.push({name:'name', params:{id: id}}) 这种方式传递过去的参数 刷新后容易消失 第二种方式 通过 query 带参   刷新页面不消失 this.$router.push({name:'name', query :{id: id}}) 原文地址:https://www.cnblogs.com/chz1905/p/11731177.html

vue路由传参query和params路由传参的区别?

相同点:router文件index.js 都是利用name属性. params传递时: params接收时利用this.$route.param进行接受: query路由传参: query接受利用this.$route.query 而展示上params路由传参像Ajax中post传参方式: query路由传参像get传参 原文地址:https://www.cnblogs.com/manban/p/12012567.html