如何在同一域中运行两个react js应用程序
how to run two react js applications in same domain
我有一个现有的react项目托管在一些领域,如http://xyz.dev现在我想在同一域中托管另一个react应用程序,但在不同的目录下,让我们说xyz.dev/newApp。问题是,我所面临的是xyz.dev的反应路由器将/newApp视为其虚拟路由,而不是重定向到newApp,而不是采取xyz.dev的内容。有没有办法告诉react-router忽略所有到/newApp的请求?
<Route path="/" component={BootstrapApp} >
<IndexRoute component={HomeApp} />
<Route path="about" component={AboutusApp} />
/* I need something like <Route ignorePath="newApp"/> */
</Route>
或者还有其他方法吗?如能及时帮助,不胜感激。
终于想通了。这与一个叫做Alias的概念有关。我们需要在服务器中创建一个Alias配置,告诉服务器从不同的目录中获取/newApp的所有内容。
Alias "/newApp" "C:/xampp/htdocs/react/xyz/newApp/www/public/"
<Directory "C:/xampp/htdocs/react/xyz/newApp/www/public/">
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride None
Require all granted
RewriteEngine On
RewriteBase /newApp
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.html [NC,L]
</Directory>
同样在newApp的路由中,我们必须将路由设置为
<Route path="/newApp/" component={BootstrapApp} >
<IndexRoute component={HomeApp} />
<Route path="about" component={AboutusApp} />
</Route>
v4表达
一种方法是使用Express应用程序的.get
方法。在.use
语句调用包含第二个应用程序的不同索引文件之前添加它。
var app = new (require('express'))();
var port = 3000;
app.get('/newapp', function(req, res) {
res.sendFile(__dirname + '/newapp/index.html');
});
app.use(function(req, res) {
res.sendFile(__dirname + '/index.html');
});
app.listen(port, function(error) {
if (error) {
console.error(error);
} else {
console.info("Listening on port %s. Open up http://localhost:%s/ in your browser.", port, port);
}
});
我希望这对你有帮助。
相关文章:
- JQuery合并了keyup和focusout两个函数
- 如何使用 node.js 比较两个 json 数组
- react-让一个元素返回两个相邻的<tr>标签
- React.js不区分同一类的两个组件
- React使用Node.js导出两个函数
- 如何让两个不相关的 React 组件一起工作
- 两个独立的 React 副本
- 在两个同级React.js组件之间传递数据
- 如何更新表示相同数据的两个不同React组件实例
- 使用React.render()渲染的两个组件之间的交互是否可能
- 如何在React JS中设置两个循环
- 更新React中两个组件之间的数据
- React / Redux—假设我们有两个单独的待办事项列表,已完成的和未完成的
- 在React JS中,一次点击选中两个复选框
- 如何在同一域中运行两个react js应用程序
- 如何在React中添加两个onClick函数
- 如何在两个视图之间导航抽屉菜单点击在React Native Android
- react本机路由器流量遇到两个具有相同密钥的子节点
- 当组件位于两个独立的文件中时,如何在react .js中插入和嵌套组件
- 为两个相似的react应用程序使用两个不同的入口点