Slug urls with Ember.js

喜夏-厌秋 提交于 2019-12-02 00:42:28

问题


How would you get post/my-title (with a custom slug) instead of posts/2 (with id) in Ember.js?

My approach was to add and use a slug in my model but it doesn't work on direct access. Using a {{link-to}} helper it works, also the slug. I assume the error lies in the PageRoute's model. Tried return this.store.find('page', {'slug': params.page_slug}) without any luck.

Example code: http://emberjs.jsbin.com/AVAgUZAb/5/edit


回答1:


You're mismatching versions of Ember Data. In the PageRoute you are using the model definition to try and find the record which is no longer correct. See https://github.com/emberjs/data/blob/master/TRANSITION.md

Additionally you really should just replace id with the slug since you've essentially rendered the idea of unique items worthless (aka slug doesn't have to be unique, but id does, so what happens when you have multiple items with the same slug?) If your slugs will always be unique, you might as well use them as the id there is no constraint that id must be numeric.

http://emberjs.jsbin.com/AVAgUZAb/9/edit



来源:https://stackoverflow.com/questions/21516440/slug-urls-with-ember-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!