Search code examples
ember.jsember-router

Handling routes which are not available


I want to handle routes which are not available by displaying something like 404 not found page. How can i do that?

for example, http://jsbin.com/oZUHiXe/1/edit in this index is available so this(http://jsbin.com/oZUHiXe/1#index) doesn't throw any error. But http://jsbin.com/oZUHiXe/1#index1 throws error in console as index1 route is not available. How to handle this case?


Solution

  • You could define a catchall route using * and do a redirect from there:

    App.Router.map(function() {
      this.route('catchAll', { path: '*:' });
    });
    
    App.CatchAllRoute = Ember.Route.extend({ 
      redirect: function() {
        alert('route not existen');
        this.transitionTo('index'); 
      }
    });
    

    Updated jsbin.

    Hope it helps.