HTML跳转路径(js中)
location.href = './login.html';
/***************************************/
if (window!=top) {
// 如果当前login.html不是最底层,那就让他变成最底层
window.top.location=location.href;
}
如果说解决了嵌套问题 但是有个小bug 第一次跳转页面还是没有解决,但是还是老样子,但只是第一次 ,第二次之后就是正常,那就在请求首页时加载完成后 发送ajax 请求后台查询是否有当前登录信息(session)回来后 用ajax中的statusCode的 状态码进行页面跳转如下:
<script>
//修复 未登录跳转bug
$(function () {
//发送ajax
$.ajax({
"url":"/user/isLogin",
"type":"get",
"statusCode": {
200:function () {
//已登录不用任何操作
},
500:function () {
//未登录 直接跳转 login.html 页面
location.href="./login.html";
}
}
})
})
</script>
/**
*@author Fang
*@create 2018/10/10 16:09
*@desc index 页面判断是否登录
**/
@GetMapping("/isLogin")
public ResponseEntity<Void> isLogin(){
User user = (User) session.getAttribute("user");
if (user!=null){
//用户已登录
return new ResponseEntity<>(HttpStatus.OK);
}else{
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}