简体   繁体   English

如何将html页面集成到React.js内置的网站中

[英]How to integrate a html page into a site built in React.js

I'm still learning React.js. 我还在学习React.js。 Recently I've built a site using React.js. 最近,我使用React.js建立了一个站点。 I was trying to add a demo page (pure html and javascript) to the react site. 我试图将演示页面(纯html和javascript)添加到React网站。 The demo page consists of an index.html, a bundle.js and a css stylesheet. 演示页面由index.html,bundle.js和CSS样式表组成。 I created a demo folder at the root of the react site and put the demo files inside that folder. 我在React网站的根目录下创建了一个演示文件夹,并将演示文件放在该文件夹中。 My question is how I can get access to the demo page by going to http://reactsite/demo/ Do I have to use react router and wrap the demo page into a react component? 我的问题是如何通过访问http:// reactsite / demo /来访问演示页面?是否必须使用react路由器并将演示页面包装到react组件中? Thanks in advance! 提前致谢!

To render pure html in with react yes you would need to use react-router to render a component at that url and then use dangerouslySetInnerHTML to read the html file as real html and not escape characters in the file 要使用react yes渲染纯HTML,您将需要使用react-router在该url上渲染组件,然后使用危险地SetInnerHTML将html文件读取为真实html而不在文件中转义字符

your route would be something like this 您的路线将是这样的

<Route path="demo" component={TemplateHTMLComponent} />

then your component would be something like this 那么你的组件将是这样的

const htmlFile = require('../some/path/to/html/file');

class TemplateHTMLComponent extends React.Component {
    render() {
        return <div dangerouslySetInnerHTML={{ __html: htmlFile}};
    }
}

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

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