用户登录
用户注册

分享至

react跳转路由页面空白怎么办

  • 作者: 偷偷放个屁
  • 来源: 51数据库
  • 2023-02-01

react跳转路由页面空白是因为写法错误,其解决办法:1、确定页面需要实现的链接;2、修改代码为“this.props.history.push({pathname:`/cardetails`,search:`?productId=${car.productId}`,state:car,})”即可。

本教程操作环境:Windows10系统、react18.0.0版、Dell G3电脑。

react跳转路由页面空白怎么办?

react 路由传参跳转时,页面空白

//页面需要实现的链接是这样的,http://localhost:4500/cardetails?productId=12676
 
//会导致空白的错误写法是
this.props.history.push({
                pathname:`/cardetails?productId=${car.productId}`,
                state:car,
            })
 
 
//正确写法是下面
this.props.history.push({
                pathname:`/cardetails`,
                search:`?productId=${car.productId}`,
                state:car,
            })
 
 
//以上是个人开发中遇到的问题,仅供参考~~

错误写法,是点击事件后,页面链接已经发生变化,但是页面内容是空白,没有报错,需手动刷新页面,才可以看的内容,

写法改变后,可以准确的定位到路由信息,解决问题。

软件
前端设计
程序设计
Java相关