【问题标题】:How to render the infoPage.js page in a seperate window when the user click on handleClick function当用户单击 handleClick 函数时,如何在单独的窗口中呈现 infoPage.js 页面
【发布时间】:2022-01-04 06:24:48
【问题描述】:

我想在用户单击以响应的 handleClick 函数时呈现 infoPage.js。感谢帮助?

infoPage.js

import React from 'react'

export default function infoPage() {
    return (
        <div>
            <h1> this is info components</h1>
        </div>
    )
}

App.js:

<button className="btn btn-primary" onClick={handleClick}>{value.title}</button>

功能:

const handleClick = () => {
   const url = infoPage;
   window.open(url, '_blank');
 } 

【问题讨论】:

  • 你能详细解释一下你的问题吗!
  • 我想在用户单击到应呈现 infoPage.js 的 handleClick 函数时呈现反应组件
  • 你想在点击右键时在新窗口中打开infoPage
  • 可以设置infoPage的路由吗?
  • 请将工作代码转发给我。感谢您的帮助

标签: reactjs react-redux react-hooks react-router


【解决方案1】:

如果你想在新窗口中/infoPage,那么试试这个代码吧!

const handleClick = () => {
           window.open('/infoPage', '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');
 } 

【讨论】:

  • InfoPage.js 数据未在新选项卡中加载,如果您有工作代码,则无法正常工作,感谢您的帮助
  • 你能尝试在window.open 中传递'location=yes,height=570,width=520,scrollbars=yes,status=yes' 那些参数吗?
  • 谢谢,尝试在新寡妇中打开信息页,但不是其中的数据,我想我也需要使用 react-router dom,但不知道如何在我的项目中实施跨度>
  • 如果我的回答对您有帮助,请接受。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-05-10
  • 1970-01-01
  • 2016-01-24
  • 1970-01-01
  • 2023-04-06
  • 1970-01-01
  • 2018-10-27
相关资源
最近更新 更多