Angular deploy-url开关问题 [英] Problems with Angular deploy-url switch
问题描述
我想将带有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:
- 每次,我都必须将基本href标记手动更改为
<base href="/mywebapp/">
.为什么在构建过程中不会自动完成此操作? - "assets"目录的静态资源的所有路径也必须手动更改为"/mywebapp/assets"(即
<img src="/mywebapp/assets/logo.png">
) - 浏览器刷新路由器链接URL(子路径)不再起作用. (即,对 http://localhost:8080/mywebapp/feature1 的角度导航有效,但是如果我想在浏览器中刷新相同的URL无效,我只能刷新根URL http://localhost:8080/mywebapp/)
- 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? - All paths to static ressources of the 'assets' directory must also changed manually to '/mywebapp/assets' (i.e.
<img src="/mywebapp/assets/logo.png">
) - 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/)
推荐答案
每当您构建时
使用
ng build --base-href .
这将解决您的问题#1& #2
This will solve ur Problems #1 & #2
问题3
此SO Post将起作用 tomcat Apache 8.5中的html5mode角.4给出404页面刷新
This SO Post will work angular html5mode in tomcat apache 8.5.4 gives 404 on page refresh
- 添加/opt/tomcat/conf/context.xml
<!-- REWRITE VALVE -->
<Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
<!-- // -->
<!-- REWRITE VALVE -->
<Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
<!-- // -->
- 在具有以下内容的特定项目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
- 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屋!