| | |
| | | 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' |
| | | |
| | | const router = createRouter({ |
| | | history: createWebHistory(import.meta.env.BASE_URL), |
| | | routes: [...mainPage, ...authPage, ...errorPage], |
| | | routes: [...mainPage, ...authPage, ...errorPage, ...h5], |
| | | }) |
| | | |
| | | router.beforeEach((to, from, next) => { |
| | | const { setLastRouteInfo } = useLoginStore() |
| | | if (!to.matched.length) { |
| | | if (to.path === '/') { |
| | | next({ path: '/main/home' }) |
| | |
| | | next({ path: '/error/404', query: { errorUrl: to.path } }) |
| | | } |
| | | } else { |
| | | if (from.name) { |
| | | setLastRouteInfo(from) |
| | | } |
| | | next() |
| | | } |
| | | }) |