Problems with Angular deploy-url switch

喜你入骨 提交于 2019-12-12 04:44:57

问题


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. 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/)

回答1:


Whenever u build

build it with

ng build --base-href .

This will solve ur Problems #1 & #2

For Problem 3

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

  1. add in /opt/tomcat/conf/context.xml

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

  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


来源:https://stackoverflow.com/questions/44132284/problems-with-angular-deploy-url-switch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!