在 React 中,使用 history.push() 跳转页面是在当前窗口进行页面跳转的。如果你想在新窗口打开链接,可以使用 JavaScript 的 window.open() 方法来实现。

以下是一个示例,展示了如何在 React 中使用 window.open() 方法打开新窗口:

import React from 'react';

const MyComponent = () => {
  const handleClick = () => {
    window.open('/newpage', '_blank');
  };

  return (
    <button onClick={handleClick}>打开新窗口</button>
  );
};

export default MyComponent;

在上面的示例中,当按钮被点击时,handleClick 函数会调用 window.open('/newpage', '_blank') 方法来打开一个新窗口,并跳转到 /newpage 路径。

请注意,浏览器可能会阻止弹出新窗口,特别是在弹出窗口的上下文中,因此这种方法可能不适用于所有的浏览器和设备

react historypush 跳转如何打开新窗口

原文地址: http://www.cveoy.top/t/topic/iZuv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录