How do I retrieve the path of a route?

强颜欢笑 提交于 2019-12-28 16:16:07

问题


Given the following Router setup:

App.Router.map(function() {
  this.resource('posts', function() {
    this.route('new');
    this.resource('post', { path: ':post_id' }, function() {
      this.route('edit');
    });
  });
});

Is it possible to obtain the path of a route?

Fictitious example:

App.Router.get('path', 'posts.new'); //=> "/posts/new"

Or with a model like:

App.Router.get('path', 'post.edit', model); //=> "/posts/1/edit"

回答1:


Try this in your console/dev tools:

App.Router.router.generate(['posts.new']);

this should output:

/posts/new

And with a model:

App.Router.router.generate(['post.edit'], postModel);

will output

/posts/1/edit

Thanks to @MilkyWayJoe's reference! https://github.com/emberjs/ember.js/blob/master/packages/ember-routing/lib/helpers/link_to.js#L112-L117 :)



来源:https://stackoverflow.com/questions/16471068/how-do-i-retrieve-the-path-of-a-route

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