如何通过React向URL动态添加查询参数?

2026-04-01 12:110阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计305个文字,预计阅读时间需要2分钟。

如何通过React向URL动态添加查询参数?

目录 + React + 向URL中添加参数 + React + 获取URL后端参数的值 + React + 向URL中添加参数 + 使用@withRouter修饰组件,将react-router的history、location、match三个对象传入p

目录
  • React 向url中添加参数
  • React 获取url后面参数的值

React 向url中添加参数

用@withRouter修饰组件,把不是通过路由切换过来的组件中,将react-router 的 history、location、match 三个对象传入props对象上

使用queryString去序列化需要添加的参数:

queryString.stringify({     name:liff,     id:1111 }) // return name=liff&id=1111

在props中获取history,并且把序列化的后的参数push进去

import queryString from "query-string"; import {withRouter} from "react-router-dom"; history.push({     queryString.stringify({         name:liff,         id:1111     }) })

React 获取url后面参数的值

由于页面跳转需要取携带的token访问数据。

阅读全文

本文共计305个文字,预计阅读时间需要2分钟。

如何通过React向URL动态添加查询参数?

目录 + React + 向URL中添加参数 + React + 获取URL后端参数的值 + React + 向URL中添加参数 + 使用@withRouter修饰组件,将react-router的history、location、match三个对象传入p

目录
  • React 向url中添加参数
  • React 获取url后面参数的值

React 向url中添加参数

用@withRouter修饰组件,把不是通过路由切换过来的组件中,将react-router 的 history、location、match 三个对象传入props对象上

使用queryString去序列化需要添加的参数:

queryString.stringify({     name:liff,     id:1111 }) // return name=liff&id=1111

在props中获取history,并且把序列化的后的参数push进去

import queryString from "query-string"; import {withRouter} from "react-router-dom"; history.push({     queryString.stringify({         name:liff,         id:1111     }) })

React 获取url后面参数的值

由于页面跳转需要取携带的token访问数据。

阅读全文