Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.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
在服务器上部署angular2的构建_Angular - Fatal编程技术网

在服务器上部署angular2的构建

在服务器上部署angular2的构建,angular,Angular,我有一个用angular2构建的web应用程序,在运行I命令ng build后,在我的文件夹结构中创建dist文件夹,现在我想在服务器上发布它 因此,我只需复制并粘贴dist文件夹,然后运行index.html 但它在开发者控制台中显示错误 Cannot match any routes. URL Segment: 'parentFolder/childFolder/dist' 最可能的错误是在我的基本URL中 PS:我已经将base href设置为 有什么想法吗 您需要复制服务器上dist文

我有一个用angular2构建的web应用程序,在运行I命令
ng build
后,在我的文件夹结构中创建dist文件夹,现在我想在服务器上发布它

因此,我只需复制并粘贴
dist
文件夹,然后运行
index.html

但它在开发者控制台中显示错误

Cannot match any routes. URL Segment: 'parentFolder/childFolder/dist'
最可能的错误是在我的基本URL中

PS:我已经将base href设置为


有什么想法吗

您需要复制服务器上dist文件夹的内容,而不是完全复制dist文件夹,并设置基本href


dist文件夹将包含
index.html
以及所有依赖项,如
资产
等。

使用此脚本替换基本标记

<script>
    document.write('<base href="' +String(document.location).replace('index.html','') + '">')
</script>

文件。写入(“”)

HI可以尝试ng build--dev,然后执行以下apache配置

<VirtualHost *:80>
    ServerName test.io
    ServerAlias test.io

    DocumentRoot your_project_path/angular2/dist
    <Directory your_project_path/angular2/dist>
            Require all granted

            RewriteEngine on
            RewriteCond %{REQUEST_FILENAME} -s [OR]
            RewriteCond %{REQUEST_FILENAME} -l [OR]
            RewriteCond %{REQUEST_FILENAME} -d
            RewriteRule ^.*$ - [NC,L]

            RewriteRule ^(.*) /index.html [NC,L]
    </Directory>
 </VirtualHost>

ServerName test.io
ServerAlias test.io
DocumentRoot您的项目路径/angular2/dist
要求所有授权
重新启动发动机
RewriteCond%{REQUEST_FILENAME}-s[或]
RewriteCond%{REQUEST_FILENAME}-l[或]
RewriteCond%{REQUEST_FILENAME}-d
重写规则^.*$-[NC,L]
重写规则^(.*)/index.html[NC,L]

但我想虽然build
是默认设置,但在更改后无论如何都无法工作。是的,dist文件夹已被删除everything@PardeepJain是的,这将是默认的,我刚才提到过,你在哪里部署它?我是apche服务器using@PardeepJain你能试着把基本参考路径改成更新后的路径吗?我猜错误是说它找不到路由结构,用这个我们可以给出一个相对路径,我已经使用了手动设置路径,比如
,但没有使用发布服务器apache??或者tomcat??我正在使用的服务器您可以参考我的答案,在下面的配置让我知道您是否需要复制dist文件夹,因为它位于服务器中(如果是tomcat,则为webapps文件夹)。此脚本将处理您在其中创建的子目录。我使用的是tomcat和/parent/dist/index.html,效果很好。