处理不可用的路线

密码劫持者

我想通过显示类似“ 404 not found”页面来处理不可用的路由。我怎样才能做到这一点?

例如,该索引中的http://jsbin.com/oZUHiXe/1/edit可用,因此,此(http://jsbin.com/oZUHiXe/1#index)不会引发任何错误。但是由于index1路由不可用,http://jsbin.com/oZUHiXe/1#index1在控制台中引发了错误。如何处理这种情况?

直观像素

您可以使用定义一个综合路由*,并从那里进行重定向:

App.Router.map(function() {
  this.route('catchAll', { path: '*:' });
});

App.CatchAllRoute = Ember.Route.extend({ 
  redirect: function() {
    alert('route not existen');
    this.transitionTo('index'); 
  }
});

更新了jsbin

希望能帮助到你。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章