如何在Ember.js中指定动态根URL? [英] How to specify a dynamic root URL in Ember.js?

查看:144
本文介绍了如何在Ember.js中指定动态根URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Ember allows for a root URL to be specified on the router here: http://emberjs.com/guides/routing/#toc_specifying-a-root-url

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

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

Is there a way to specify a dynamic URL like: /:region/:locale/?

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

The rootURL assignment seems to only accept a literal string.

资源(包括Ember)正在从共同目录(如 / assets / )加载。

Assets (including Ember) are being loaded from a common directory like /assets/.

推荐答案

您可以在内部动态设置 rootURL Router.init 方法,例如

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();
});

这篇关于如何在Ember.js中指定动态根URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆