mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
feat: add layout of chat and login
This commit is contained in:
@@ -1,8 +1,35 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
redirect: '/login'
|
||||
},
|
||||
{
|
||||
name: 'Login',
|
||||
path: '/login',
|
||||
component: () => import('@/pages/login/index.vue')
|
||||
}, {
|
||||
name: 'Chat',
|
||||
path: '/chat',
|
||||
component: () => import('@/pages/chat/index.vue'),
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [],
|
||||
routes,
|
||||
})
|
||||
router.beforeEach((to) => {
|
||||
const token = localStorage.getItem('token')
|
||||
if (to.fullPath !== '/login') {
|
||||
return token ? true : { name: 'Login' }
|
||||
} else {
|
||||
return token ? { name: 'Chat' } : true
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user