我正在使用 React 和 Node.js 开发一个电子商务网站。我面临下面描述的两个问题。
我有两个不同的主
.html
文件用于管理端和前端端。因此,我使用内置的 React 管理模板,其中index.html
在项目启动时加载。我的问题是如何加载另一个主.html
用于前端设计?我想使用 Node.js 作为后端。因此,我无法将 Node.js 与 React 前端或管理端集成,如果 React 应用程序运行,它们将运行。
任何建议或解决方案步骤都将受到高度赞赏。
最佳答案
这是第一个想法的非常基本的概念:
const AdminIndexPage = children => (<section className="AdminIndexPage">{children}</section>)
const PublicIndexPage = children => (<section className="PublicIndexPage">{children}</section>
const App = props => {
if(props.indexPageToShow === 'admin'){
return <AdminIndexPage {...props} />
}else{
return <PublicIndexPage {...props} />
}
}
这是第二个想法的非常基本的概念:
index.html
<html>
<head>
<script src="index.js"></script>
</head>
<body>
<div id="AdminPageIndex"></div>
<div id="PublicPageIndex"></div>
</body>
</html>
index.js
import {AdminPageIndex, PublicPageIndex} from './pages'
ReactDOM.render(AdminPageIndex, document.getElementById('AdminPageIndex'))
ReactDOM.render(PublicPageIndex, document.getElementById('PublicPageIndex'))
关于node.js - react js : Rendering multiple index html in a single page applications,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57643625/