How to specify a dynamic root URL in Ember.js?

让人想犯罪 __ 提交于 2019-12-05 09:27:31

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

  }
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!