v1.0.0
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import type { App } from 'vue'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import { createRouter, createWebHashHistory } from 'vue-router'
|
||||
import { setupPageGuard } from './permission'
|
||||
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'Home',
|
||||
// component: () => import('@/views/home/Layout.vue'),
|
||||
component: () => import('@/views/home/index.vue'),
|
||||
// children: [
|
||||
|
||||
// {
|
||||
// path: '/edit/:noteId?',
|
||||
// name: 'EditNote',
|
||||
// component: () => import('@/views/home/index.vue'),
|
||||
// },
|
||||
// ],
|
||||
},
|
||||
|
||||
{
|
||||
path: '/login',
|
||||
name: 'login',
|
||||
component: () => import('@/views/login/index.vue'),
|
||||
},
|
||||
|
||||
{
|
||||
path: '/404',
|
||||
name: '404',
|
||||
component: () => import('@/views/exception/404/index.vue'),
|
||||
},
|
||||
|
||||
{
|
||||
path: '/500',
|
||||
name: '500',
|
||||
component: () => import('@/views/exception/500/index.vue'),
|
||||
},
|
||||
|
||||
{
|
||||
path: '/:pathMatch(.*)*',
|
||||
name: 'notFound',
|
||||
redirect: '/404',
|
||||
},
|
||||
|
||||
{
|
||||
path: '/test',
|
||||
name: 'test',
|
||||
component: () => import('@/views/exception/test/index.vue'),
|
||||
},
|
||||
|
||||
// adminRouter,
|
||||
]
|
||||
|
||||
export const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes,
|
||||
scrollBehavior: () => ({ left: 0, top: 0 }),
|
||||
})
|
||||
|
||||
setupPageGuard(router)
|
||||
|
||||
export async function setupRouter(app: App) {
|
||||
app.use(router)
|
||||
await router.isReady()
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import type { Router } from 'vue-router'
|
||||
import { useUserStore } from '@/store/modules/user'
|
||||
|
||||
export function setupPageGuard(router: Router) {
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
// const authStore = useAuthStoreWithout()
|
||||
const userStore = useUserStore()
|
||||
// 非管理员路由拦截
|
||||
if (userStore.userInfo.role !== 1 && to.path.includes('admin'))
|
||||
next({ name: '404' })
|
||||
|
||||
else
|
||||
next()
|
||||
|
||||
// if (!authStore.session) {
|
||||
// try {
|
||||
// const data = await authStore.getSession()
|
||||
// if (String(data.auth) === 'false' && authStore.token)
|
||||
// authStore.removeToken()
|
||||
// if (to.path === '/500')
|
||||
// next({ name: 'Root' })
|
||||
// else
|
||||
// next()
|
||||
// }
|
||||
// catch (error) {
|
||||
// if (to.path !== '/500')
|
||||
// next({ name: '500' })
|
||||
// else
|
||||
// next()
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// next()
|
||||
// }
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user