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

2024-04-18

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

App.Router.reopen({
  rootURL: '/blog/'
});

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

The rootURL赋值似乎只接受文字字符串。

资产(包括 Ember)从公共目录加载,例如/assets/.


您可以设置rootURL动态地在Router.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();
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Ember.js 中指定动态根 URL? 的相关文章

随机推荐