2017-08-30 62 views
0

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

所以我简单地复制和粘贴有dist文件夹,运行index.html

却是露出在开发者控制台错误

Cannot match any routes. URL Segment: 'parentFolder/childFolder/dist' 

最有可能的错误是我的基本URL。

PS:我已经设置基本href为<base href="./">

什么想法?

+0

你发布哪个服务器apache?或者tomcat? – Robert

+0

apche服务器我正在使用 –

+0

你可以参考我的答案,下面的配置 – Robert

回答

0

您需要复制服务器上dist文件夹的内容,而不是dist文件夹,并设置基准href <base href="./">

dist文件夹将有index.html加上所有的依赖就像assets

+0

但我想建立''是默认情况下,反正无法改变后工作。是的dist文件夹已经有一切 –

+0

@PardeepJain你会默认我刚刚提到它,你在哪里部署它? –

+0

apche服务器我正在使用 –

-1

这个脚本

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

再次不起作用 –

+0

你正在得到什么错误? –

+0

得到相同的错误 –

0

HI取代基标签可以可以尝试纳克建立--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>