admin管理员组文章数量:1335084
Ember allows for a root URL to be specified on the router here:
App.Router.reopen({
rootURL: '/blog/'
});
Is there a way to specify a dynamic URL like: /:region/:locale/
?
The rootURL
assignment seems to only accept a literal string.
Assets (including Ember) are being loaded from a mon directory like /assets/
.
Ember allows for a root URL to be specified on the router here: http://emberjs./guides/routing/#toc_specifying-a-root-url
App.Router.reopen({
rootURL: '/blog/'
});
Is there a way to specify a dynamic URL like: /:region/:locale/
?
The rootURL
assignment seems to only accept a literal string.
Assets (including Ember) are being loaded from a mon directory like /assets/
.
- 1 Would you mind explaining the workflow a bit of how you would expect it to behave? – Kingpin2k Commented Jan 6, 2014 at 21:00
3 Answers
Reset to default 7You can set rootURL
dynamically within Router.init
method, e.g.
App.Router.reopen({
init: function() {
// set rootURL using regex to extract appropriate
// rootURL based on current window location
this.set('rootURL',
window.location.pathname.match('/[^/\]*/[^/\]*/')[0]);
this._super();
});
You'll have to declare you're root URL '/', and then create the rest as routes/resources under that.
I was able to acplish this within an instance-initializer - I set the root url as a meta environment variable using ember-cli-meta-options, then applied it to the router
export default {
name: "router",
initialize: function( instance ) {
var router = instance.container.lookup('router:main');
var options = instance.container.lookup('session:env');
router.rootURL = options['root'];
}
};
本文标签: javascriptHow to specify a dynamic root URL in EmberjsStack Overflow
版权声明:本文标题:javascript - How to specify a dynamic root URL in Ember.js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742385172a2464885.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论