为什么刷新页面会空白?我做了持久化,routes里面的数据是一直存在的,但是好像刷新后虽然有routes数据,但是之前添加到router里面的动态路由也消失了?
router.beforeEach(async (to, form, next) => {
const { setAndFormatMenu } = useUserStore()
if (to.path === '/login') {
return next()
}
const { routes } = storeToRefs(useUserStore())
if (routes.value.length === 0) {
const newRoutes = await setAndFormatMenu()
router.addRoute({
path: '/',
component: () => import('@/components/Layout/index.vue'),
children: newRoutes,
})
const firstPage = getFirstPage(routes.value)
return next(firstPage)
}
next()
})
export default router