Why do nested resource routes reset the namespace in Ember?

前端 未结 1 1762
臣服心动
臣服心动 2021-01-20 11:04

Let\'s say I have a Photo model and a Post model, and I want both of those to have Comment\'s. In Rails, my routes would look like thi

相关标签:
1条回答
  • 2021-01-20 11:44

    TL;DR Resources must be unique due to the transitioning paradigm, and really you're just over-writing the comments resource.

    It's because when you transition to routes you don't explicitly call out an entire path.

    this.transitionTo('photo', photo);
    
    {{#link-to 'photo' photo}} My photo{{/link-to}}
    

    Because of this resources must be unique.

    If you were at the root of your app and wanted to jump 2 levels deep, to a photo you would just use this.transitionTo('photo', photo), and would NOT use this.transitionTo('photos.photo', photo)

    If you are transitioning to a resource that is multiple dynamic resources deep you just send in multiple models. this.transitionTo('foo', bar, baz).

    As was implied, you could force people to state an entire path while doing transitionTo/link-to, but the authors decided to punish the smaller percent of people with duplicate resources vs punish everyone into defining the entire path while transitioning.

    Additionally it's understood that foo.bar represents resource.route in Ember. I wouldn't consider this an argument for why it was architected as it was, more of a statement about it.

    @resource 'posts', ->
       @resource 'post', { path: '/:post_id' }
       @route 'foo'
    
    this.transitionTo('posts.foo');
    
    0 讨论(0)
提交回复
热议问题