forked from natuka/web.puabadge.com
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.1 KiB
50 lines
1.1 KiB
// https://router.vuejs.org/zh/ |
|
import { createRouter, createWebHashHistory } from 'vue-router' |
|
import NProgress from 'nprogress' |
|
import 'nprogress/nprogress.css' |
|
// 导入路由组件 |
|
import oauth from '@/views/oauth/index.vue' |
|
import { useUserStore } from '@/stores/user' |
|
|
|
NProgress.configure({ showSpinner: true, parent: '#app' }) |
|
|
|
// 定义路由,每个路由都需要映射到一个组件 |
|
const routes = [ |
|
{ |
|
path: '/', |
|
name: 'oauth', |
|
component: oauth, |
|
meta: { |
|
needGuard: false, |
|
}, |
|
}, |
|
] |
|
|
|
mergeRoutes(routes) |
|
|
|
// 创建路由实例并传递 `routes` 配置 |
|
const router = createRouter({ |
|
history: createWebHashHistory(process.env.VUE_APP_PUBLIC_PATH), |
|
routes, |
|
}) |
|
|
|
router.beforeEach((_to, _from, next) => { |
|
const userStore = useUserStore() |
|
NProgress.start() // start progress bar |
|
const needGuard = _to.meta.needGuard |
|
if (!needGuard) { |
|
if (userStore.isLoggedIn()) |
|
window.location.href = '/' |
|
else |
|
next() |
|
} else { |
|
next() |
|
} |
|
}) |
|
|
|
router.afterEach(() => { |
|
NProgress.done() // finish progress bar |
|
}) |
|
|
|
// 导出路由实例,并在 `main.ts` 挂载 |
|
export default router
|
|
|