问题
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:
- 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/)
回答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
- add in /opt/tomcat/conf/context.xml
<!-- REWRITE VALVE -->
<Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
<!-- // -->
- 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