Angular deploy-url 开关的问题 [英] Problems with Angular deploy-url switch

查看:33
本文介绍了Angular deploy-url 开关的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将带有 angular-frontend 的 spring-boot webapp 部署到 tomact-server.我使用 angular-cli 和以下命令构建了 angular 应用程序

I want to deploy my spring-boot webapp with angular-frontend to a tomact-server. I build the angular app with angular-cli and the following commando

ng build --deploy-url /mywebapp/

该应用可以运行,但仍然存在以下问题:

The app works but following problems still exist:

  1. 每次我必须手动将基本 href 标记更改为 <base href="/mywebapp/">.为什么这不会在构建过程中自动完成?
  2. 所有指向assets"目录的静态资源的路径也必须手动更改为/mywebapp/assets"(即 <img src="/mywebapp/assets/logo.png">)
  3. 路由器链接 URL(子路径)的浏览器刷新不再起作用.(即到 http://localhost:8080/mywebapp/feature1 的角度导航有效,但如果我想在浏览器中刷新相同的 URL 不起作用.我只能刷新根 URL http://localhost:8080/mywebapp/)
  1. Each time I have to change manually the base href tag to <base href="/mywebapp/">. Why is this not done automatically in the build process?
  2. All paths to static ressources of the 'assets' directory must also changed manually to '/mywebapp/assets' (i.e. <img src="/mywebapp/assets/logo.png">)
  3. Browser refresh of router links URLs (subpaths) does not work anymore. (i.e. angular navigation to http://localhost:8080/mywebapp/feature1 works but if I want to refresh the same URL in the browser it does not work. I can only refresh the root URL http://localhost:8080/mywebapp/)

推荐答案

Whenever u build

Whenever u build

构建它

ng build --base-href .

这将解决您的问题 #1 &#2

This will solve ur Problems #1 & #2

对于问题 3

此 SO 帖子将起作用tomcat apache 8.5 中的 angular html5mode.4 在页面刷新时给出 404

This SO Post will work angular html5mode in tomcat apache 8.5.4 gives 404 on page refresh

  1. 加入/opt/tomcat/conf/context.xml

<代码><Valve className="org.apache.catalina.valves.rewrite.RewriteValve"/><!--//-->

  1. 在特定项目的 WEB-INF 文件夹中添加 rewite.config 文件,内容如下例如.在/opt/tomcat/webapps/projectName/WEB-INF/rewrite.config<代码>RewriteCond %{REQUEST_URI} !^.*\.(bmp|css|gif|htc|html?|ico|jpe?g|js|pdf|png|swf|txt|xml|svg|eot|woff|woff2|ttf|地图)$重写规则 ^(.*)$/index.html [L]这是做什么的对于此路由请求中的每一个,它都会重定向到 index.html
  1. add rewite.config file in specific project WEB-INF folder with below content for eg. on /opt/tomcat/webapps/projectName/WEB-INF/rewrite.config RewriteCond %{REQUEST_URI} !^.*\.(bmp|css|gif|htc|html?|ico|jpe?g|js|pdf|png|swf|txt|xml|svg|eot|woff|woff2|ttf|map)$ RewriteRule ^(.*)$ /index.html [L] What this does is for each of this route requests it redirects to index.html

这篇关于Angular deploy-url 开关的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆