簡體   English   中英

Ember.js路由

[英]Ember.js routing

我正在努力尋找任何不錯的Ember.js路由示例。

我應該使用這樣的插件還是我個人很喜歡的樣子這個

我看到有一個路由集合作為State對象的一部分,但是我找不到如何使用它的任何示例。

路由最近已在核心Ember.js中提供,請參見Tom Dale的博客文章

核心開發人員Yehuda Katz撰寫了有關新路由功能用法的要點 這是一本不錯的書,並且除了路由之外,還介紹了如何與控制器集成。

為了獲得基本思想,下面是摘自要旨的代碼示例:

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

我在應用程序中使用了萌芽路由 ,因為:

有關文檔,請查看spoutcore-routing測試

我強烈推薦該指南在ember網站上: http : //emberjs.com/guides/router_primer/

我相信此內容是非常新的-幾周前當我第一次嘗試理解Ember路由時,我當然沒有注意到它。

灰燼路由在聖誕節期間完全改變。 他們發布了一些新文檔來提供幫助,但刪除了所有舊教程。 我猜測舊的做事方式(在前面的答案中)將被棄用。 http://emberjs.com/guides/routing/

編輯:由於Ember.js路由器的重大更改,此答案已過時, 因為1.0 PRE-RELEASE左右 現代版本的ember.js應該使用標准的路由准則

我想這(至少現在)非常個人化。 我喜歡ghempton的ember-routemanager。 如果您需要幫助,我可以為您提供幫助。 連同他的余燼布局程序包,它們可以很好地協同工作。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM