小编AxS*_*Sch的帖子

history.push() 和 props.location.state 导致“无法读取未定义的属性‘状态’”

问题描述

I am using react-router-dom together with react functional components. I am trying to pass data with "history.push", which is not working.

The redirection to another page with "history.push" itself is working great. BUT the problem is: passing data via "state: {...}" to a component causes: "Cannot read property 'state' of undefined" when I try to access it with "props.location.state" within the component.

I have tried different variations of defining the route.

Code

app.js

import React from 'react';
import PageList …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-router

2
推荐指数
2
解决办法
7907
查看次数

标签 统计

javascript ×1

react-router ×1

reactjs ×1