我使用Tomcat来托管路由器的角度应用程序。但是,当我尝试使用路由时,我得到了一个404错误(主/开始)。
Tomcat正在本地主机上运行:9443/main。
路由器配置:
{path: 'getting-started', component: GettingStartedComponent},
{path: '', component: codeComponent},
{path: 'main', component: codeComponent}主要工作正常。开始工作了。
尝试过这个解决方案,但没有成功:https://medium.com/@nithin.biliya/deploying-angular-application-on-tomcat-server-fixing-deep-linking-issue-577565fe303d
在角配置和baseHref中尝试了不同的index.html。
据https://angular.io/guide/deployment称,
如果应用程序使用角路由器,则
路由应用程序必须回到index.html,您必须配置服务器,以便在请求它没有的文件时返回应用程序的主机页(index.html)。路由应用程序应该支持“深度链接”。
现在,我怎么才能把它放在猫上呢?
发布于 2022-11-09 09:29:12
对于任何对这个问题有意见的人。它是由
--如果应用程序使用角路由器,则必须配置服务器,以便在请求它没有的文件时返回应用程序的主机页(index.html)。
对我有效的解决方案:
eclipse项目中的,该项目的角度构建服务于Tomcat:
在META文件夹中,编辑文件context.xml并添加RewriteValve:
<Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />如果您没有context.xml -创建它并添加以下xml:
<?xml version="1.0" encoding="utf-8"?>
<Context>
<Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
</Context>在WEB中,创建文件rewrite.config (此文件包含用于URL重写的规则,并由tomcat用于URL重写)。在rewrite.config内部,复制以下内容:
RewriteCond %{SERVLET_PATH} !-f
RewriteRule ^/(.*)$ /index.html 这将返回应用程序的主机页(index.html),当请求它没有的文件时。
现在,如果问题没有解决-取决于您的项目设置,您可能需要更改angular.json中的angular.json或更改RewriteRule。
https://stackoverflow.com/questions/74336941
复制相似问题