听着,我不知道我是否在标题中很好地表达了自己,但它是这样的。
我做了一个角度应用程序,客户可以通过我的网站购买健身房的计划。所以我做了一个路由方案,网址中的第一件事是健身房的id(从我的数据库中恢复),然后是"/plans“。
例如:localhost:4200/000162/plans
问题来了,我为我的项目做了一个构建,文件夹结构类似于dist/__projectName__/__projectContent__。
使用命令ng build --prod --base-href /vysor_vendas_online/app/
然后,我将所有的projectContent放在我的Apache服务器文件夹中的www/vysor_vendas_online/app/路径下,并尝试在我的浏览器中运行。
localhost:8080/vysor_vendas_online/app/index.html?000162/plans但是什么都没有发生,它停留在白屏上,没有控制台错误,但当我尝试使用Angular服务器localhost:4200/000162/plans时,它可以工作。
我在这里做错了什么?我应该如何访问我在代码中指定的路由?
发布于 2020-02-21 04:19:49
正如deployment官方文档所说的那样
路由的应用程序必须回退到index.html
Apache:向如下所示的.htaccess文件添加重写规则(https://ngmilk.rocks/2015/03/09/angularjs-html5-mode-or-pretty-urls-on-apache-using-htaccess/):
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.htmlhttps://stackoverflow.com/questions/60327592
复制相似问题