定义一个多分段捕获所有路由在ember.js [英] Defining a multi segmented catch all route in ember.js

查看:94
本文介绍了定义一个多分段捕获所有路由在ember.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ember.js,如果导航到与资源不匹配的URL,我想创建一个捕获所有路由以将用户发送回应用程序的根目录。 (我正在使用历史API)我已经实现了这样:

  App.Router.map(function(){
this.resource('things',function(){
this.resource('thing',{path:':thing_id'});
});
这个。 route('catchAll',{path:':*'});
this.route('catchAll',{path:':* /:*'});
this.route catchAll',{path:':* /:* /:*'});
});

App.Router.reopen({
location:'history'
});

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

App.IndexRoute = Ember.Route.extend({

});

我的问题是:我可以定义一个匹配任何没有解决的路径的路线无论路径中的段数如何,都可以使用资源?



我正在使用Ember.VERSION:1.0.0-rc.1

解决方案

经过一些琐事之后,我想我已经找到了一个解决方案: *: ,如

  this.route('catchAll',{path:'*:'} ); 

我设置了这个小提琴来演示它是如何工作的。


I am using Ember.js and I would like to create a catch all route to send the user back to the root of the application if they navigate to a URL that does not match a resource. (I am using the history API) I have implemented this like so:

App.Router.map(function() {
    this.resource('things', function() {
        this.resource('thing', {path:':thing_id'}); 
    });
    this.route('catchAll', { path: ':*' });
    this.route('catchAll', { path: ':*/:*' });
    this.route('catchAll', { path: ':*/:*/:*' });
});

App.Router.reopen({
  location: 'history'
});

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

App.IndexRoute = Ember.Route.extend({ 

});

My question is: Can I define a single catch all route that will match any path that has not resolved to a resource irrespective of the number of segments in the path?

I am using Ember.VERSION : 1.0.0-rc.1

解决方案

After some fiddling i think I've found a solution: the *: seems to do the trick, like

this.route('catchAll', { path: '*:' });

I set up this fiddle to demonstrate how it works.

这篇关于定义一个多分段捕获所有路由在ember.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆