Angular adding extra logic to 404 handling on non angular routes Angular adding extra logic to 404 handling on non angular routes angularjs angularjs

Angular adding extra logic to 404 handling on non angular routes


Depending on the router of your choice, you could do something like the following (which is what we've done (well, not precisely this, but close)):

ui-router

app.config(function ($urlRouterProvider) {  var regx = /\/#\//; // match against /#/  $urlRouterProvider.otherwise(function ($state, $location) {    if (!regx.test($location.path()) { // if no match      $state.go('customHandlingState', /** params **/, /** configuration **/ });       // Transition to your custom handler state, with optional params/config.     }  });});

You could pair this up with custom stateChange[Start|Stop|Error|Success] handlers in the run block of your app to customise it to your liking.

I would supply an example of how to do this with ngRoute, but I gave up on ngRoute two years ago and haven't looked back since. As such I have no suggestion to give, nor was I able to find a solution to the problem you present.

I would strongly suggest you scrap the S3 portion of this recipe as it will make your life a lot easier when it comes to client side routing (speaking from personal experience here, it's my opinion on the matter - not fact) and handle your 404's/500's on the client with custom state handlers.

If need be you could hook into some logging service and store some data whenever a client/person ends up in an erroneous state.

I suppose my 'counter question' is; What do you gain from using S3 redirect rules? So as to get a better understanding for the needs and goals here.


Some reference material to go along:


I would suggest using routeParamshttps://docs.angularjs.org/api/ngRoute/service/$routeParams

the route would look like this:/mysite/:cid

then access the id with the controller:$routeParams.cid

I hope this could help


You can manually configure your server to always serve your index.html(your main html file which includes reference to angular script) on all incoming http requests. Client routing will be handled by Angular