簡體   English   中英

將dist文件夾部署到tomcat服務器上時,angular2路由不起作用

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

我在prj-routing-final項目中使用ng-build --prod --aot命令用angular-cli生成了dist文件夾,並將其部署到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中可用的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存儲庫

請幫助我。

您將需要配置您的Web服務器,以將所有未知(404)請求重定向到index.html,這將允許Angular應用程序隨后將您的用戶路由到所需的路由/視圖。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM