使用 react-router v4 的 this.props.history.push 打开窗口?

A.c*_*com 4 reactjs react-router react-router-v4 react-router-dom

我知道我们可以使用 Link 标签并传入 target="_blank" 就像

<Link to="/" target="_blank">Hello World</Link>
Run Code Online (Sandbox Code Playgroud)

但我很难发现我可以用 this.props.history.push 做到这一点......我正在使用它来传递路径名和搜索字符串......

    let searchString = queryString.stringify({
      rangeEnd: data.programEnd,
    });

    this.props.history({
      pathname: `/machines/${machineId}`,
      search: searchString,
      target: "_blank // need something like this, not seeing it in docs
    });
Run Code Online (Sandbox Code Playgroud)

Ris*_*abh 9

历史推送在同一窗口中更改地址。

一种选择是使用 window.open()

const url = `#/machines/${machineId}?${searchString}`;
window.open(url);
Run Code Online (Sandbox Code Playgroud)