| | |
| | | import authPage from '@/router/auth/index.js' |
| | | import errorPage from '@/router/error/index.js' |
| | | import mainPage from '@/router/main/index.js' |
| | | import h5 from '@/router/h5/router.js' |
| | | |
| | | import { useLoginStore } from '@/stores/login.js' |
| | | import { useSessionStore } from '@/stores/session.js' |
| | | const router = createRouter({ |
| | | history: createWebHistory(import.meta.env.BASE_URL), |
| | | routes: [...mainPage, ...authPage, ...errorPage, ...h5], |
| | | routes: [...mainPage, ...authPage, ...errorPage], |
| | | }) |
| | | |
| | | router.beforeEach((to, from, next) => { |
| | |
| | | next({ path: '/error/404', query: { errorUrl: to.path } }) |
| | | } |
| | | } else { |
| | | next() |
| | | if (to.meta.loginRequired) { |
| | | const { userInfo } = useSessionStore() |
| | | const { setLoginDialogVisible } = useLoginStore() |
| | | if (userInfo.id) { |
| | | next() |
| | | } else { |
| | | setLoginDialogVisible(true) |
| | | next(false) |
| | | } |
| | | } else { |
| | | next() |
| | | } |
| | | } |
| | | }) |
| | | |