Reputation: 1895
I have published an angular app under the Tomcat and it works fine but as soon as the user refresh the page Tomcat answers that he can't find the URL (previous handled with the angular-routing), to the other hand instead using localhost 'ng serve' it works fine.
any idea how to solve it ?
thanks
Upvotes: 0
Views: 538
Reputation: 3011
The application deep links will not work without the redirect rule on the server. All the deep links have to redirect to the application index.html
by the server.
To setup the tomcat to redirect any deep links -
1. Configure the RewriteValve in server.xml
Edit the ~/conf/server.xml to add the below Valve inside the Host section as below –
...
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
...
</Host>
...
2. Write the rewrite rule in rewrite.config
Create directory structure – ~/conf/Catalina/localhost/ and create the rewrite.config file inside it with the below content. Note - here I am considering /hello
as the context path of the application.
RewriteCond %{REQUEST_PATH} !-f
RewriteRule ^/hello/(.*) /hello/index.html
After setting this up restart the tomcat server and you can hit the deep links of the application which will route to the correct components inside the angular application.
You can refer to this post for more details.
Upvotes: 0