最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to specify a dynamic root URL in Ember.js? - Stack Overflow

programmeradmin0浏览0评论

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/.

Share Improve this question edited Jun 22, 2017 at 8:15 laser 1,37613 silver badges14 bronze badges asked Jan 6, 2014 at 19:40 Danny GarciaDanny Garcia 8412 gold badges9 silver badges24 bronze badges 1
  • 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
Add a ment  | 

3 Answers 3

Reset to default 7

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

  }
};
发布评论

评论列表(0)

  1. 暂无评论