简体   繁体   English

如何让网站显示在我的 reactjs 应用程序的正文中?

[英]How do I get a website to display in the body of my reactjs app?

I created a site that I hosted on the web, now I would like to create a button that allows the user to access this site directly in my reactjs application without having to be redirected to another page in my navigator.我创建了一个托管在网络上的站点,现在我想创建一个按钮,允许用户直接在我的 reactjs 应用程序中访问该站点,而无需重定向到导航器中的另一个页面。 For this I wrote the following code:为此,我编写了以下代码:

<Button
        component={NavLink}
        activeClassName={classes.activeBtn}
        to="/searchEngine"
        className={classes.buttonItemMiddle}
      >
        {location.pathname == '/searchEngine' ? (
          <Home fontSize="large" style={{ color: 'rgb(0,133,243)' }} />
        ) : (
          <HomeOutlined fontSize="large" />
        )}
      </Button> 

and I inserted this code in my App.js file:我在我的App.js文件中插入了这段代码:

<Route path='/searchEngine' component={() => { 
                          window.location.replace('https://gkwhelps.herokuapp.com'); 
                          return null;
                          }}/>

It did create a button but whenever I click on it I automatically quit my reactjs app and get redirected to the other site.它确实创建了一个按钮,但是每当我单击它时,我都会自动退出我的 reactjs 应用程序并重定向到另一个站点。 Yet what I would like is for my site to be wrapped in my reactjs application.然而,我希望我的网站能够包含在我的 reactjs 应用程序中。 I have uploaded the solution on some stack overflow questions and on this blog but without success.我已经在一些堆栈溢出问题和这个博客上上传了解决方案,但没有成功。

Off the top of my head, an iFrame would be the best way to achieve this.在我的脑海中,iFrame 将是实现这一目标的最佳方式。

Here is an example of how it could work:这是它如何工作的示例:

<iframe src="https://gkwhelps.herokuapp.com" title="App"></iframe>

You may also need to apply styling to make the iFrame fit to the entire page or just a certain area.您可能还需要应用样式以使 iFrame 适合整个页面或仅适合某个区域。

You can learn more about iFrames at this W3 Schools article .您可以在这篇W3 Schools 文章中了解有关 iFrame 的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM