定义router的js文件
找到注册router的下方加上beforeEach
//创建路由
const router = createRouter({
history: createWebHashHistory(process.env.BASE_URL),
routes,
});
//看这里
router.beforeEach((to,from)=>{
console.log(to,'to')
console.log(from,'from')
//这里写具体操作
})