I'm building an application with Grails 3.3.2 and Angular (currently Angular 5).
I've set up the Grails to give the index.html, which is located in src/main/webapp, when requests are made for the default URL (e.g. http://localhost:8080). I've also set up the server to process all requests started with /api/ as REST endpoints.
Everything works well. The Angular app is loaded and the user interacts with the app and navigate through the routes correctly, but when the user refreshes the page (e.g. pressing F5), he gets the 404 message (page not found).
This happens because a request is made for the server with the currently URL (e.g. http://localhost:8080/users), which is a valid route in the Angular app, but it does not exist in the server.
I'd like to know if it's possible to the server gives the same index.html, no matter the URL, except URLs started with /api/, and the Angular navigates to the correct route based on the URL. For example, if the user refreshes the page when it's in the users page, the server supplies the index.html and the Angular navigates to the users page.
I've got a set up which every request to the server, except the default URL and URLs started with /api/, goes to a controller and this controller redirects to the default URL. This solved the problem with the 404 but when this happens, the Angular app goes to the first route, instead of the route which the user was in.
I appreciate so much if someone could help me.