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'];
}
};