【问题标题】:Problems with Angular deploy-url switchAngular 部署 URL 开关的问题
【发布时间】:2017-10-23 06:10:56
【问题描述】:

我想将带有 angular-frontend 的 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 的角度导航有效,但如果我想在浏览器中刷新相同的 URL,它不起作用。我只能刷新根 URL http://localhost:8080/mywebapp/

【问题讨论】:

  • 试试base href="."这应该可以解决你的问题#1 & #2
  • 添加为答案
  • 问题 #1 & #2 似乎可以用 base href="." 解决。对于问题 #3,这对我有用:stackoverflow.com/questions/42599176/…
  • 这个问题只能用firefox浏览器解决。使用 Internet Explorer 这个不起作用,它总是解析为 root 而不是 '/mywebapp/'。你有什么建议吗?

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


【解决方案1】:

无论何时构建

用它构建它

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2017-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多