私域操盘手 - 增加路由守卫,拦截所有未登录的页面及页面请求

This commit is contained in:
柳清爽
2025-05-16 10:11:08 +08:00
parent 47b32684b9
commit 4934460997
6 changed files with 63 additions and 5 deletions

View File

@@ -95,6 +95,17 @@ export default function DeviceDetailPage() {
})
const [tabChangeLoading, setTabChangeLoading] = useState(false)
// 添加登录检查
useEffect(() => {
const token = localStorage.getItem('token')
if (!token) {
// 如果没有token重定向到登录页面并携带当前页面URL作为回调
const currentPath = window.location.pathname + window.location.search
router.push(`/login?redirect=${encodeURIComponent(currentPath)}`)
return
}
}, [router])
useEffect(() => {
if (!params.id) return