繁体   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