简体   繁体   English

将dist文件夹部署到tomcat服务器上时,angular2路由不起作用

[英]angular2 routing not working when you deployed dist folder onto tomcat server

I generated dist folder in my project prj-routing-final with angular-cli with command ng-build --prod --aot and deployed on to tomcat server. 我在prj-routing-final项目中使用ng-build --prod --aot命令用angular-cli生成了dist文件夹,并将其部署到tomcat服务器上。 i was able to navigate to all routes http://localhost:8081/dist/ and view them without reloading. 我能够导航到所有路由http://localhost:8081/dist/并查看它们而无需重新加载。 Once if i navigate to http://localhost:8081/dist/recipes/0 and reload the page this error coming up 如果我导航到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

I am not getting any errors if i serve with ng serve . 如果我与ng serve一起使用,我没有任何错误。 i was able navigate to all routes, reload the pages, move back and forth. 我能够导航到所有路线,重新加载页面,来回移动。

I also tried serving dist with Http-server available in https://www.npmjs.com/package/http-server getting same kind of error after reloading No webpage was found for the web address: http://localhost:8080/recipes/0 GitHub repo of my project 我还尝试使用https://www.npmjs.com/package/http-server中可用的Http-server来提供dist服务,重新加载后出现相同的错误。 No webpage was found for the web address: http://localhost:8080/recipes/0 我项目的 No webpage was found for the web address: http://localhost:8080/recipes/0 GitHub存储库

Please kindly help me. 请帮助我。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM