1

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/)
7
  • 1
    try base href="." this should solve your problem #1 & #2 Commented May 23, 2017 at 10:33
  • 1
    for problem#3 : stackoverflow.com/questions/39468479/… Commented May 23, 2017 at 10:34
  • added as answer Commented May 23, 2017 at 14:49
  • problem #1 & #2 seems to be solved with base href=".". For problem #3 this one worked for me: stackoverflow.com/questions/42599176/… Commented May 23, 2017 at 14:51
  • the problem is only solved with firefox browser. with internet explorer this one does not work, it always resolves to root instead of '/mywebapp/'. Do you have any suggestions? Commented May 30, 2017 at 17:34

1 Answer 1

0

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
Sign up to request clarification or add additional context in comments.

2 Comments

this one should also work: stackoverflow.com/questions/42599176/…
@surfspider i wrote this answer on based of tomcat & This answer is based on spring boot configuration. u can upvote :p

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.