简体   繁体   English

从ReactJS渲染HTML静态页面

[英]Render HTML Static Pages from ReactJS

I am trying to build a website/web ( similar with Airbnb) app with ReactJS and RoR as backend endpoint. 我正在尝试使用ReactJS和RoR作为后端端点来构建一个网站/网站(与Airbnb类似)应用程序。 My problem is that I am new to the whole javascript ecosystem and I have some questions. 我的问题是我是整个javascript生态系统的新手,我有一些问题。 I have a full html5 static theme ( or tamplate ) with all the css, html files and so on, and i want to use react to make some content dynamic indise this theme html pages, and some other ( like about page and help ) keep it static html page. 我有一个完整的html5静态主题(或tamplate),其中包含所有css,html文件等,我想使用react使该主题html页面的某些内容动态化,而其他一些主题(如about page和help)保持不变它是静态的html页面。 My qustion is that, can I somehow with react-router or some other package add links to my static-pages from react? 我的问题是,我能否以某种方式使用react-router或其他一些包将来自react的链接添加到我的静态页面? or I have to render everything with react and convert it to components? 还是我必须使用react渲染所有内容并将其转换为组件? In short, can i have react app mixed with static html pages? 简而言之,我可以将React应用与静态html页面混合吗? or everything should become a single page application? 还是一切都应该成为一个页面应用程序?

Everything in react should be component based. 反应中的所有内容都应基于组件。 React router is based on component too. React Router也基于组件。 So you can't serve static Html with react router until you wrap them into a react component. 因此,除非将它们包装到react组件中,否则您不能将它与react router一起使用。

Technicaly you can render html inside react component. 从技术上讲,您可以在react组件内部呈现html。 It can be accomplished via dangerouslySetInnerHTML 可以通过dangerouslySetInnerHTML来完成

function createMarkup() {
  return {__html: '<h1>Some text</h1>'};
}

function MyComponent() {
  return <div dangerouslySetInnerHTML={createMarkup()} />;
}

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

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