在ReactJS中,可以使用window.open()方法在新窗口或新标签页中打开一个URL。

如果您想要在使用navigate函数时打开一个新窗口,可以使用window.open()来实现。例如:

import { useNavigate } from 'react-router-dom';

const MyComponent = () => {
  const navigate = useNavigate();

  const openNewWindow = () => {
    window.open('/new-page', '_blank');
  };

  return (
    <div>
      <button onClick={() => navigate('/new-page')}>打开新页面</button>
      <button onClick={openNewWindow}>在新窗口打开</button>
    </div>
  );
};

export default MyComponent;

在上面的例子中,当点击"打开新页面"按钮时,页面会在当前窗口中导航到/new-page。而当点击"在新窗口打开"按钮时,会在新窗口或新标签页中打开/new-page

reactjs 使用navigate = useNavigate 如何在新窗口打开

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

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