angular - Angular deploy-url 开关的问题

标签 angular tomcat spring-boot angular-ui-router angular-cli

我想将带有 Angular 前端的 spring-boot webapp 部署到 tomact-server。我使用 angular-cli 和以下命令构建 Angular 应用

ng build --deploy-url /mywebapp/

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

  1. 每次我必须手动将基本 href 标签更改为 <base href="/mywebapp/"> .为什么这不是在构建过程中自动完成的?
  2. “assets”目录的所有静态资源路径也必须手动更改为“/mywebapp/assets”(即 <img src="/mywebapp/assets/logo.png">)
  3. 路由器链接 URL(子路径)的浏览器刷新不再起作用。 (即,到 http://localhost:8080/mywebapp/feature1 的 Angular 导航有效,但如果我想在浏览器中刷新相同的 URL,则它不起作用。我只能刷新根 URL http://localhost:8080/mywebapp/)

最佳答案

无论何时构建

构建它

ng build --base-href .

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

对于问题 3

这个 SO 帖子会起作用 angular html5mode in tomcat apache 8.5.4 gives 404 on page refresh

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

<!-- REWRITE VALVE --> <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|map)$ RewriteRule ^(.*)$ /index.html [L] 这是做什么的 对于每个此路由请求,它都重定向到 index.html

关于angular - Angular deploy-url 开关的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44132284/

相关文章:

css - 自动大小列取决于 css/angular 中多行的最大大小

javascript - Angular2 toString 无法获取类的第三个属性

angular - 如何观察rxjs中的属性变化?

java - Tomcat NIO 和 Sendfile 清理文件发送

java - Google APP Engine 和 cloud sql::无法在 Google cloud sql 中连接 Spring boot 应用程序(我的 sql)

javascript - 如何转换 RXJS Observable 中的属性

Tomcat 6 无法访问应用程序

Spring tx :annotation-driven ignores mode when load time weaving is enabled in tomcat

java - 我们可以安全地将 `tomcat.addTldSkipPatterns("*.jar")` 用于使用嵌入式 tomcat 的纯后端 spring 引导服务吗

升级到 2.4.0 后,Spring Cloud 配置客户端无法从配置服务器获取/加载配置文件