文件资源管理平台_前台&后台_开发文档
登录
- 前台 - 路由守卫对除了 - /login进行认证,判断- localStorage是否向服务器认证- 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18- const router = createRouter({ 
 history: createWebHashHistory(),
 routes
 })
 // 在路由导航前进行身份验证
 router.beforeEach((to, from, next) => {
 const isAuthenticated = localStorage.getItem('auth'); // 从LocalStorage中获取用户信息(令牌等)
 if (to.meta.requiresAuth && !isAuthenticated) {
 // 如果访问的页面需要身份验证并且用户未登录,则重定向到登录页面
 next('/login');
 } else {
 // 用户已登录或访问不需要验证的页面,则允许访问
 next();
 }
 });
 export default router
 
- 后台 
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 吕小布の博客!
 评论


