0

My angular 2 app runs fine on my local node server. However when the dist/prod contents are deployed to a server (to be precise websphere liberty server) The url just works fine for once. When I try to reload it, it gives me File not found exception. Also the deep routes for e.g http://localhost:5555/myapp/route1/somefeature/extra doesn't work and throws the same exception.

Just to confirm:

  1. I am using proper basehref (for e.g '/myproduct/')
  2. The server.xml contains proper contextpath ('/myproduct/')
  3. Thus the url http://someserver:8080/myproduct/myapp runs fine but when refreshed or deep routes are hit, it throws file not found exception

I have gone through this post Angular2 routing / deep linking not working with Apache 404 and need the similar kind of settings in my server.xml (for liberty websphere server)

Since I do not want to go back to include old implementation of hash(#) urls, Any help in this regard is much appreciated.

Community
  • 1
  • 1
Rajeev
  • 1
  • 2
  • we moved to express server to serve my app. Even though on express we have to write this special line to redirect all request to index.html. `app.use(express.static(path.join(__dirname, 'prod'))); app.get('/*', function(req, res){ res.sendFile(path.join(__dirname, 'prod') + '/index.html'); });` – Rajeev Feb 22 '18 at 21:05

1 Answers1

1

Did you try in web.xml?

<error-page>
    <error-code>404</error-code>
    <location>/</location>
</error-page>
user648399
  • 36
  • 5
  • thanks for the input. However just an update.. I moved to express server :) – Rajeev Feb 22 '18 at 21:04
  • This solution worked for me. In my case, my angular app is packaged in ear file and its routing was not working. The only route working was ''. After adding in web.xml in my Angular app, all routes started working. Thank you very much. – Atul Kumbhar Oct 15 '19 at 07:29