Last active
October 28, 2023 08:55
-
-
Save srikarn/e89cbb459c454754654b1975e8ca50c0 to your computer and use it in GitHub Desktop.
Spring boot configuration to forward to index page on 404
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
ErrorViewResolver redirectToFrontEndOn404() { | |
return ( request, status, model ) -> status == HttpStatus.NOT_FOUND | |
? new ModelAndView("forward:/index.html", Collections.<String, Object>emptyMap(), HttpStatus.OK) | |
: null; | |
} | |
This is necessary on page refresh to avoid showing 404 or error pages | |
This forward also maintains the client route path, so angular will route to the correct route on reload. | |
This needs a complementary route config on the frontend, to redirect to default route on 404 on the client side |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment