// Teacher role route guard for Vue Router // Import this guard in your router entry (e.g., src/router/index.js) and call `router.beforeEach(teacherGuard)` export default function teacherGuard(to, from, next) { // Assume user role is stored in localStorage after login const role = localStorage.getItem('role'); // List of routes that require teacher role (prefix /guide) const teacherOnly = to.path.startsWith('/guide'); if (teacherOnly && role !== 'teacher') { // Redirect to a safe page, e.g., home or login return next({ path: '/', replace: true }); } return next(); }