Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在同一域中运行两个react js应用程序_Javascript_Url_Reactjs_Routes_React Router - Fatal编程技术网

Javascript 如何在同一域中运行两个react js应用程序

Javascript 如何在同一域中运行两个react js应用程序,javascript,url,reactjs,routes,react-router,Javascript,Url,Reactjs,Routes,React Router,我有一个现有的react项目托管在某个域中,如 现在我想在同一个域中托管另一个react应用程序,但位于不同的目录中,比如xyz.dev/newApp。我面临的问题是,xyz.dev的react路由器将/newApp视为其虚拟路由,并且它没有重定向到newApp,而是接收xyz.dev的内容。 有没有办法告诉react路由器忽略所有到/newApp的请求 <Route path="/" component={BootstrapApp} > <IndexRoute com

我有一个现有的react项目托管在某个域中,如 现在我想在同一个域中托管另一个react应用程序,但位于不同的目录中,比如xyz.dev/newApp。我面临的问题是,xyz.dev的react路由器将/newApp视为其虚拟路由,并且它没有重定向到newApp,而是接收xyz.dev的内容。 有没有办法告诉react路由器忽略所有到/newApp的请求

<Route path="/" component={BootstrapApp} >
    <IndexRoute component={HomeApp} />
    <Route path="about" component={AboutusApp} />
    /* I need something like <Route ignorePath="newApp"/> */
</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);
  }
});

我希望这能有所帮助:)

终于找到了答案。它与一个名为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>
Alias”/newApp“C:/xampp/htdocs/react/xyz/newApp/www/public/”
选项-索引+FollowSymLinks+多视图
不允许超限
要求所有授权
重新启动发动机
重写库/新应用程序
RewriteCond%{REQUEST_FILENAME}-s[或]
RewriteCond%{REQUEST_FILENAME}-l[或]
RewriteCond%{REQUEST_FILENAME}-d
重写规则^.*$-[NC,L]
重写规则^.*$index.html[NC,L]
此外,在您的newApp路线中,我们必须将路线设置为

<Route path="/newApp/" component={BootstrapApp} >
    <IndexRoute component={HomeApp} />
    <Route path="about" component={AboutusApp} />
</Route>


只有使用这两种配置,我们才能在同一个域中运行两个完全不同的React应用程序。

实际上,我在apache服务器上使用的是React js应用程序