feat:first commit
This commit is contained in:
38
src/router.ts
Normal file
38
src/router.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { createRouter, RouterMount, totalNextRoute } from 'uni-simple-router'
|
||||
import { getToken, getUserInfo } from '@/utils/util'
|
||||
|
||||
const router = createRouter({
|
||||
platform: process.env.VUE_APP_PLATFORM,
|
||||
routes: [...ROUTES, { path: '*', redirect: '/pages/404' }]
|
||||
})
|
||||
|
||||
router.beforeEach(async (to: totalNextRoute, from: totalNextRoute, next) => {
|
||||
next()
|
||||
// const loginPathList = ['/pages/login/index', '/pages/login/protocol', '/pages/login/again']
|
||||
// const token = getToken()
|
||||
// const userInfo = getUserInfo()
|
||||
//
|
||||
// if ((!token && !userInfo) || (token && !userInfo)) {
|
||||
// // 用户未登录
|
||||
// if (!loginPathList.includes(to.path)) {
|
||||
// const redirect = encodeURIComponent(JSON.stringify(to.fullPath || '/pages/index/index'))
|
||||
// next({ path: `/pages/login/index?redirect=${redirect}` })
|
||||
// } else {
|
||||
// next()
|
||||
// }
|
||||
// } else {
|
||||
// // 用户已登录
|
||||
// if (to.path === '/pages/login/index') {
|
||||
// // 已登录用户访问登录页面,跳转至首页
|
||||
// next({ path: '/pages/index/index' })
|
||||
// }
|
||||
// // 其他情况,正常跳转
|
||||
// next()
|
||||
// }
|
||||
})
|
||||
|
||||
router.afterEach((to: totalNextRoute, from: totalNextRoute) => {
|
||||
// console.info('afterEach to', to, 'afterEach from', from)
|
||||
})
|
||||
|
||||
export { router, RouterMount }
|
||||
Reference in New Issue
Block a user