将dist文件夹部署到tomcat服务器上时,angular2路由无法正常工作

时间:2017-06-29 18:41:19

标签: angular tomcat angular2-routing angular-cli

我在项目 prj-routing-final 中使用 angular-cli 生成 dist 文件夹,并使用命令ng-build --prod --aot进行部署到tomcat服务器。我能够导航到所有路线http://localhost:8081/dist/并查看它们而无需重新加载。如果我导航到http://localhost:8081/dist/recipes/0并重新加载页面,则会出现此错误

HTTP Status 404 – Not Found  
Type Status Report
Message /dist/recipes/0
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/8.5.14

如果我使用ng serve投放,我没有收到任何错误。我能够导航到所有路线,重新加载页面,来回移动。

我还尝试在https://www.npmjs.com/package/http-server中使用 dist 提供 dist ,在重新加载后遇到同样的错误 No webpage was found for the web address: http://localhost:8080/recipes/0 GitHub repo of my project

请帮助我。

1 个答案:

答案 0 :(得分:0)

您需要配置您的Web服务器以将所有未知(404)请求重定向到index.html,这将允许Angular应用程序将您的用户路由到所需的路由/视图。

相关问题