【发布时间】:2021-10-20 11:17:42
【问题描述】:
我正在将一个状态从 Link 元素传递到另一个组件,如果我单击它可以正常工作,但是如果我尝试在新选项卡中打开链接,则状态不会被传递。我该如何解决这个问题?
参考代码:
<Link to={{pathname:"/open-page", state:{key: 'hello'}}}/>
openPage.js
import React, { useEffect, useRef } from 'react';
import { bool } from 'prop-types';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { createWidget } from '@typeform/embed';
import { injectIntl, intlShape } from '../../util/reactIntl';
export const OpenPageComponent = props => {
const { intl, scrollingDisabled } = props;
console.log('state', props.location.state.key); //undefined on opening in a new tab
【问题讨论】:
标签: reactjs react-router react-router-dom