首页 文章

使用Angular配置Tomcat 8

提问于
浏览
1

我正在尝试在我的本地apache tomcat 8服务器上部署我的角度应用程序 .

我使用了ng build --prod并在这里复制粘贴dist的结果 .

Location of my app on server

我把 <base href="/caquiweb/"> 放到我的index.html .

因此,我可以访问我的应用程序,并且路由工作,但404在手动将浏览器中的URL更改为定义的路由器路由时 .

Working url by using routerLink

404 manually changing from browser

我认为我必须配置我的服务器,但我真的不知道该怎么做 .

提前致谢

1 回答

  • 1

    从我的角度来看,最容易的解决

    • tomcat/webapps/caquiweb 中添加 WEB-INF/web.xml ,其中包含以下内容:
    <web-app>
        <error-page>
             <error-code>404</error-code>
             <location>/index.html</location>
         </error-page>
    </web-app>
    

    这样,每次找不到URL时,Tomcat都会重定向到 index.html ,然后导致Angular使用组件路由器处理它 .

相关问题