如何检索路由的路径? [英] How do I retrieve the path of a route?
本文介绍了如何检索路由的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
App.Router.map(function(){
this.resource('posts',function(){
this.route('new');
this.resource('post',{path:':post_id'}, function(){
this.route('edit');
});
});
});
是否可以获取路线的路径?
虚构示例:
App.Router。 get('path','posts.new'); // => / posts / new
或者使用如下模型:
App.Router.get('path','post.edit',model); // => / posts / 1 / edit
解决方案
您的控制台/开发工具:
App.Router.router.generate(['posts.new']);
这应该输出:
/ posts / new
并带有一个模型:
App.Router.router.generate(['post.edit'],postModel);
将输出
code> / posts / 1 /编辑
感谢@ MilkyWayJoe的参考! https:/ /github.com/emberjs/ember.js/blob/master/packages/ember-routing/lib/helpers/link_to.js#L112-L117 :)
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"
解决方案
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 :)
这篇关于如何检索路由的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文