Search code examples
ember.jsember-router

Ember.js new router custom slug usage


I am using this router code:

Ngin.Router.map(function(match) {
    "use strict";
    this.route('index', {path: '/'});
    this.route('article', {path: '/technical/:url/'});
});

I need to somehow get the clicked element url in the serialize method, so that I can get that article's data from the model. I looks obvious how one should do this in the case of an id but I have no clue about how I should do this with a url.


Solution

  • As always with Ember, the solution is simple. The only thing one needs to get used to, is that Ember is not jQuery, and that context in Ember is (or should be) data, aka models.

    Ngin.ArticleRoute = Ember.Route.extend({
        serialize: function(model) {
            "use strict";
            return {
                url: model.get("url") + "/"
            };
        }
    });
    

    And context has to be set like this in this case:

    {{#linkTo "article" article}}{{article.title}}{{/linkTo}}
    

    This is it. As simple as that.