【问题标题】:ember routing and with trying to add a new route not workingember 路由并尝试添加新路由不起作用
【发布时间】:2014-01-08 15:02:27
【问题描述】:

我刚刚启动 Ember,但遇到了名为 posts.images 的路由问题。

在我的路由器中,我有:

this.resource('posts', function(){
    this.resource('images', { path: ':post_id' });
    this.resource('newpost', { path: 'new' });
    this.resource('post', { path: ':post_id' });
});

我的路线是:

Hex.PostImagesRoute = Ember.Route.extend({  // same with Hex.PostsImagesRoute
    model: function(params) {
        console.log('alert postimages');
        return Hex.Post.findById(params.post_id);
    }
});

在我的模板中我有:

{{#link-to 'posts.images' id}}images{{/link-to}}

但我收到以下错误:

Assertion failed: The attempt to link-to route 'posts.images.index' failed. The router did not find 'posts.images.index' in its possible routes: 'loading', 'e

我已阅读http://emberjs.com/guides/routing/defining-your-routes/,但不确定我做错了什么。任何帮助,将不胜感激。

谢谢

【问题讨论】:

    标签: ember.js


    【解决方案1】:

    向下滚动一点:

    注意:如果您使用 this.resource 定义资源并且不提供函数,则隐式 resource.index 路由未创建

    http://emberjs.com/guides/routing/defining-your-routes/

    【讨论】:

    • 谢谢,文档上的措辞不是很好。你能告诉我我做错了什么吗?
    • 当然,posts.index 是(隐式)创建的,因为您已将函数传递给路由器中的 post 资源。在这个函数中,您已经定义了子路由。为了隐式创建posts.images.index 路由,您必须将一个函数传递给图像资源。像这样:this.resource('images', { path: ':post_id' }, function(){ //... }); 这有点傻,因为函数本身可以留空..
    • 你刚刚救了我的朋友。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-22
    相关资源
    最近更新 更多