jeudi 29 octobre 2015

Ember router can transition to but not handle a url

Using Ember 2.1.0 with EmberData, I'm making a small blogging app. It has two routes

Router.map(function(){
  this.route("posts": "/");
  this.route("post", {path: '/:seo_friendly_link'});
}

The seo_friendly_link looks like this

 /2015/10/28/my-blog-post-title/

In the index route, I display a list of posts with links to each post. If I click a link, the Ember app will transition to the post that I clicked on. I emphasize transitionto-- the routing goes through that method in Ember router.

The problem:

However, if I drop that same url into the browser, I get an UnrecognizedURLError (before the model or even the beforeModel hook are called for the post). If I drop the url into the browser, the routing goes through the handleURL method on Ember Router, which doesn't happen if I click a link from the homepage. So my Ember app can transition to my seo_friendly_link, but not handle that url.

I'm not sure why.

Question: How can I create a route to recognize that link?

Code

There is a property on the Post model called

   seo_friendly_link: DS.attr('string')

In /routes/post, I call the serialize method to create that parameter from the model property

  serialize: function(model, params){
     seo_friendly_link: model.get("seo_friendly_link");
  }




Aucun commentaire:

Enregistrer un commentaire