【发布时间】:2019-08-08 10:03:02
【问题描述】:
我一直在尝试将我的 Angular 7 应用程序部署到 HTTPD Apache 2 服务器。 这些是我采取的步骤:
- 为我的项目设置虚拟主机
- 构建 --> ng build --prod
-
按照here的指示创建和配置.htaccess:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.html [L] 像这样配置我的 app-routing.module.ts:
导入:[RouterModule.forRoot(routes ,{onSameUrlNavigation: 'reload'})]
我的主页可以正常工作,但是当我尝试浏览其他路线时,例如http://myhostname/users/crud,它不再起作用了。 我在这里错过了什么吗?
谢谢。
【问题讨论】:
-
很可能你需要在你的 Angular 应用中设置
base href。 -
你有没有看过这个问题:stackoverflow.com/questions/34816025/…?
-
谢谢@Wandrille。但我放弃了这一点,因为我现在不是一个活跃的 PHP 开发人员。我尝试了您的答案,但我使用了带有嵌入式 apache tomcat 的 Springboot,并且我通过 Zuul 和 application.properties 处理了路由。而且效果很好:)!