如何在Ember.js中指定动态根URL?

Dan*_*cia 5 javascript web-applications url-routing ember.js

Ember允许在路由器上指定根URL:http://emberjs.com/guides/routing/#toc_specifying-a-root-url

App.Router.reopen({
  rootURL: '/blog/'
});
Run Code Online (Sandbox Code Playgroud)

有没有办法指定动态URL,如:/:region/:locale/

rootURL分配似乎只接受一个字符串.

资产(包括Ember)正在从像这样的公共目录加载/assets/.

jes*_*nko 7

您可以rootURLRouter.init方法中动态设置,例如

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();
});
Run Code Online (Sandbox Code Playgroud)


Jim*_*ows 1

您必须声明您的根 URL '/',然后在其下创建其余部分作为路由/资源。