1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import { createRouter, createWebHistory } from 'vue-router'
- import { authLogin } from '@/utils/axios/auth'
- import LoginRoutes from './login'
- import HomeRoutes from './home'
- import Material from './material'
- // 路由配置
- const routes = [
- ...LoginRoutes,
- {
- path: '/index',
- name: 'Index',
- component: () => import('@/views/Index.vue'),
- children: [...HomeRoutes, ...Material],
- },
- {
- path: '/',
- redirect: '/home',
- },
- {
- //访问不存在的路由的时候,跳转到首页
- path: '/:pathMatch(.*)',
- redirect: '/home',
- },
- ]
- const router = createRouter({
- // history: createWebHashHistory(),
- history: createWebHistory(),
- routes,
- })
- router.beforeEach((to, _from, next) => {
- if (to.name === 'Login') {
- next()
- } else {
- if (authLogin()) {
- next()
- } else {
- router.push('/login')
- }
- }
- })
- export default router
|