vue+springboot+springsecurity 后端session超时重定向到了login页面,但前台没反应,把整个页面响应回来了。怎么让页面跳转到登录
直接在接口超时后,用this.$router.push(登录页路由地址)就可以了
在axios封装拦截器,进行路由跳转
可以换一种
后端session超时,返回code:301,前端部分axios拦截到301,通过this.$router.push({ name: 'login' })
跳转到登录路由
看文档这部分: https://github.com/axios/axios#request-config
里边有个配置:
// `beforeRedirect` defines a function that will be called before redirect.
// Use this to adjust the request options upon redirecting,
// to inspect the latest response headers,
// or to cancel the request by throwing an error
// If maxRedirects is set to 0, `beforeRedirect` is not used.
beforeRedirect: (options, { headers }) => {
if (options.hostname === "example.com") {
options.auth = "user:password";
}
},
在这里阻止 axios 的重定向,手动控制页面重定向
axios 重定向问题解决_Axios 源码中值的学习的核心知识点
https://blog.csdn.net/weixin_34717586/article/details/112363107?utm_term=axios%E9%87%8D%E5%AE%9A%E5%90%91&utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~all~sobaiduweb~default-0-112363107-null-null&spm=3001.4430