2012-04-14 77 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/