Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

ember.js - How do I retrieve the path of a route?

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"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...