0

调用时:

FlowRouter.url("myRouteName");

我正在获取服务器的 IP 地址,即

"http://XX.XXX.XX.XXX/loggedin/my-route"

而不是 FQDN,即

"http://example.com/loggedin/my-route"

知道如何正确配置它吗?

谢谢。


4

1 回答 1

0

回答我自己的问题。来源

Router.prototype.url = function() {
  // We need to remove the leading base path, or "/", as it will be inserted
  // automatically by `Meteor.absoluteUrl` as documented in:
  // http://docs.meteor.com/#/full/meteor_absoluteurl
  var completePath = this.path.apply(this, arguments);
  var basePath = this._basePath || '/';
  var pathWithoutBase = completePath.replace(new RegExp('^' + basePath), '');
  return Meteor.absoluteUrl(pathWithoutBase);
};

所以看起来 FlowRouter 正在使用Meteor.absoluteUrl.

现在可以设置绝对路径Meteor.absoluteUrl.defaultOptions.rootUrl = "http://example.com"但是这对我来说不是正确的方法,因为我的应用程序实际上可以提供多个域名。

所以我必须编写自己的函数,从客户端提取 FQDN,即席。

flowRouterUrl = function(id, params, queryParams) {
    return window.location.protocol + "//" + window.location.host + FlowRouter.path(id, params, queryParams);
}

flowRouterUrl("myRoute");

返回

http://example.com/loggedin/my-route

这就是我所追求的。

于 2017-01-18T09:28:19.387 回答