2012-04-14 81 views
7

我正在努力寻找任何良好的Ember.js路由示例。Ember.js路由

我是否应该使用像this这样的插件或者我个人喜欢this的外观?

我看到有一个路由集合作为状态对象的一部分,但我找不到如何使用它的任何示例。

回答

1

编辑:由于Ember.js路由器的重大变化,这个答案已经过时,因为约1.0 PRE-RELEASE。现代版本的ember.js应use the standard routing guidelines

我想这是(现在leas)非常个人。 我喜欢ghempton的余烬路线管理员。如果你需要一些帮助,我可以帮你。 加上他的余烬布局包,他们一起工作很好。

http://codebrief.com/2012/02/anatomy-of-a-complex-ember-js-app-part-i-states-and-routes/

+0

我已经走了ember-routemanager和layoutmanager。我喜欢他们一起玩的方式。 如果出现任何问题,我会提供补丁。 – dagda1 2012-04-16 14:01:14

+4

据我可以告诉这种技术不再适用于包含本地路由的ember.js 0.9.8.1,请参阅下面的* * *官方* * *解答的pangrantz答案;) – jskulski 2012-06-04 03:30:21

+0

是的,当然,这是正确的现在,我写这个答案时,它不可用。 – Luan 2012-06-05 01:09:03

3

我用我的应用程序sproutcore-routing因为:

有关文档,请查看spoutcore-routing tests

+0

我不太确定,SC命名空间在Ember 0.9.6中被废除了。 这意味着它们不再一起玩,并且是离开Sproutcore的一般举措的一部分。 IMO我必须强调。 我可以只是命名空间的别名,但我想知道如果其中一个新项目不会更好。 我原本打算使用sproutcore-routing直到0.9.6 – dagda1 2012-04-16 14:00:47

21

最近在核心Ember.js中提供了路由,请参阅Tom Dale的blog post

核心开发者Yehuda Katz写了一个gist关于新的路由功能的使用。这是一个很好的阅读,除了路由还说明它如何与控制器集成。

获得基本的想法,这里是从要点采取了代码示例:

App.Router = Ember.Router.extend({ 
    root: Ember.State.extend({ 
    index: Ember.State.extend({ 
     route: '/', 
     redirectsTo: 'calendar.index' 
    }), 

    calendar: Ember.State.extend({ 
     route: '/calendar', 

     index: Ember.State.extend({ 
     route: '/' 
     }), 

     preferences: Ember.State.extend({ 
     route: '/preferences' 
     }) 
    }), 

    mail: Ember.State.extend({ 
     route: '/mail', 

     index: Ember.State.extend({ 
     route: '/' 
     }), 

     preferences: Ember.State.extend({ 
     route: '/preferences' 
     }) 
    }) 
    }) 
}); 

// If the user navigates to the page with the URL 
// www.myapp.com/, you will start in the root.calendar.index state. 
// The redirection to the calendar.index state will cause the URL 
// to be updated to www.myapp.com/calendar 

router.transitionTo('preferences'); 

// URL => www.myapp.com/calendar/preferences 

router.transitionTo('mail.preferences'); 

// URL => www.myapp.com/mail/preferences 

router.transitionTo('index'); 

// URL => www.myapp.com/mail 
3

Ember路由在圣诞节完全改变。他们发布了一些新的文档来帮助,但删除了所有旧的教程。我猜测旧的做法(在之前的答案中)将被弃用。 http://emberjs.com/guides/routing/