输入不应输入的块

时间:2015-02-12 11:08:47

标签: html angularjs

我对angularjs $位置有疑问。 我有一个auth解释器,如果服务器返回401错误(未经授权),它会重定向到登录页面。 我已经在app.js中输入了auth解释器,并且还在app.js帐户中加载了数据。这意味着我必须在加载帐户数据之前创建一个if块,否则在索引屏幕上它将尝试加载帐户数据,服务器将返回未授权的并将重定向到登录屏幕;这意味着我永远无法访问index.html页面。 这是if块:

if($location.path() != "/" 
   || $location.path() != "" 
   || $location.path() != "/register" 
   || $location.absUrl() != "http://localhost:8080/ipersonally/index.html")

因此,如果我转到“localhost:8080 / ipersonally / index.html#”或“localhost:8080 / ipersonally / index.html#/”,它会将我带到索引页面。但是,如果我进入“localhost:8080 / ipersonally / index.html”,它会将我重定向到登录页面。我认为这必须是因为它进入if块并尝试加载帐户数据。所以我做了:

console.log($location.absUrl());

if块内。这在浏览器控制台日志“http://localhost:8080/ipersonally/index.html”中返回。 如果我做了,它如何进入if块  $location.absUrl() != "http://localhost:8080/ipersonally/index.html" 在if块? 提前致谢, 克里斯

2 个答案:

答案 0 :(得分:0)

由于您或条件“http://localhost:8080/ipersonally/index.html”不等于“/ register”,因此您的if语句的条件已满。

答案 1 :(得分:0)

应该是

if($location.path() != "/" 
   && $location.path() != "" 
   && $location.path() != "/register" 
   && $location.absUrl() != "http://localhost:8080/ipersonally/index.html")