If I understand correctly what you want, you should do the following:
hard redirect the browser (bypassing angular routing) otherwise, with something like this:
$routeProvider .otherwise({ controller: function () { window.location.replace('/404');
if you have a regular one-page application in which all server requests are redirected to the same SPA entry point, you need to configure it on your server to make a routing exception for your 404 user page, which should also be served with 404 status.
Otherwise, I canβt understand how you will do this using only the history API, without an external request, because all this in angular routing is to bypass external requests.
If you want non-existent routes to return 404, you must configure your server to match all your angular routes and otherwise return 404.
Tiborg
source share