简体   繁体   English

Ember.js路由

[英]Ember.js routing

I am struggling to find any good Ember.js routing examples. 我正在努力寻找任何不错的Ember.js路由示例。

Should I use an addon like this or I personally like the look of this ? 我应该使用这样的插件还是我个人很喜欢的样子这个

I see there is a routes collection as part of the State object but I cannot find any examples of how to use it. 我看到有一个路由集合作为State对象的一部分,但是我找不到如何使用它的任何示例。

Routing has been recently made available in core Ember.js, see Tom Dale's blog post . 路由最近已在核心Ember.js中提供,请参见Tom Dale的博客文章

Core developer Yehuda Katz wrote a gist about the usage of the new routing feature. 核心开发人员Yehuda Katz撰写了有关新路由功能用法的要点 It's a good read, and besides routing also states how it can be integrated with controllers. 这是一本不错的书,并且除了路由之外,还介绍了如何与控制器集成。

To get the basic idea, here's a code example taken from the 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

I use sproutcore-routing in my apps because: 我在应用程序中使用了萌芽路由 ,因为:

For documentation have a look at the spoutcore-routing tests 有关文档,请查看spoutcore-routing测试

I strongly recommend this guide on the ember site: http://emberjs.com/guides/router_primer/ 我强烈推荐该指南在ember网站上: http : //emberjs.com/guides/router_primer/

I believe this content is very new-- I certainly didn't notice it a couple of weeks ago when I first started trying to understand Ember routing. 我相信此内容是非常新的-几周前当我第一次尝试理解Ember路由时,我当然没有注意到它。

Ember routing changed entirely over Christmas. 灰烬路由在圣诞节期间完全改变。 They posted some new documentation to help, but removed all the old tutorials. 他们发布了一些新文档来提供帮助,但删除了所有旧教程。 I'm guessing the old ways of doing things (in the previous answers) will be deprecated. 我猜测旧的做事方式(在前面的答案中)将被弃用。 http://emberjs.com/guides/routing/ http://emberjs.com/guides/routing/

Edit: Due to significant changes in the Ember.js router, this answer is obsolete since around the 1.0 PRE-RELEASE . 编辑:由于Ember.js路由器的重大更改,此答案已过时, 因为1.0 PRE-RELEASE左右 MOdern versions of ember.js should use the standard routing guidelines 现代版本的ember.js应该使用标准的路由准则

I guess this is (at leas for now) very personal. 我想这(至少现在)非常个人化。 I like ghempton's ember-routemanager. 我喜欢ghempton的ember-routemanager。 If you need some help with it I could help you. 如果您需要帮助,我可以为您提供帮助。 Together with his ember-layout package as well, they work nice together. 连同他的余烬布局程序包,它们可以很好地协同工作。

http://codebrief.com/2012/02/anatomy-of-a-complex-ember-js-app-part-i-states-and-routes/ 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