2016-04-29 48 views
0

我目前使用铁路路由器。在我的模板文件,我通过检索模板中的网址或路由路径

var url = Router.current().url 

var url = Router.current().originalUrl 

这些回报的电流路径检索URL没有协议和主机名。然而,当你刷新页面(浏览器刷新)时,同样的方法返回整个url(协议,主机名和路径)。

http://localhost:3000/your/current/path 

如何可靠地检索整个网址或路径路径?

回答

0

可以使用Iron.Location对象,你可以使用

Iron.Location.get().rootUrl --> 'http://localhost:3000' 
Iron.Location.get().path --> '/your/current/path' 
Iron.Location.get().port --> 3000 
Iron.Location.get().protocol --> 'http:' 
Iron.Location.get().queryObject ---> return query object 
Iron.Location.get().hostname --> 'localhost' 
Iron.Location.get().host --> 'localhost:3000' 

Meteor.absoluteUrl() will give the root url as well. 
+0

感谢您的答复,这里是一些财产。我如何导入“铁”? –

+0

你使用流星1.3吗? –

+0

回答我自己的问题'从'流星/铁:核心'导入{铁};' –