mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-05-12 02:21:06 +08:00
178 lines
4.2 KiB
TypeScript
178 lines
4.2 KiB
TypeScript
import { createRouter, createWebHashHistory } from 'vue-router'
|
|
import { configureNProgress, doneNProgress, startNProgress } from '@/api/nprogress'
|
|
import store from '@/store'
|
|
|
|
// Nprogress
|
|
configureNProgress()
|
|
|
|
// Router
|
|
const router = createRouter({
|
|
history: createWebHashHistory(import.meta.env.BASE_URL),
|
|
scrollBehavior(to, from, savedPosition) {
|
|
// 如果页面有缓存那么恢复其位置, 否则始终滚动到顶部
|
|
if (to.meta.keepAlive && savedPosition)
|
|
return savedPosition
|
|
return { top: 0 }
|
|
},
|
|
routes: [
|
|
{ path: '/', redirect: '/dashboard' },
|
|
{
|
|
path: '/',
|
|
component: () => import('../layouts/default.vue'),
|
|
children: [
|
|
{
|
|
path: 'dashboard',
|
|
component: () => import('../pages/dashboard.vue'),
|
|
meta: {
|
|
requiresAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: 'ranking',
|
|
component: () => import('../pages/ranking.vue'),
|
|
meta: {
|
|
keepAlive: true,
|
|
requiresAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: 'resource',
|
|
component: () => import('../pages/resource.vue'),
|
|
meta: {
|
|
requiresAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: 'subscribe-movie',
|
|
component: () => import('../pages/subscribe-movie.vue'),
|
|
meta: {
|
|
requiresAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: 'subscribe-tv',
|
|
component: () => import('../pages/subscribe-tv.vue'),
|
|
meta: {
|
|
requiresAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: 'calendar',
|
|
component: () => import('../pages/calendar.vue'),
|
|
meta: {
|
|
requiresAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: 'downloading',
|
|
component: () => import('../pages/downloading.vue'),
|
|
meta: {
|
|
requiresAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: 'history',
|
|
component: () => import('../pages/history.vue'),
|
|
meta: {
|
|
requiresAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: 'site',
|
|
component: () => import('../pages/site.vue'),
|
|
meta: {
|
|
requiresAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: 'plugins',
|
|
component: () => import('../pages/plugin.vue'),
|
|
meta: {
|
|
requiresAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: 'setting',
|
|
component: () => import('../pages/setting.vue'),
|
|
meta: {
|
|
requiresAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: '/browse/:paths+',
|
|
component: () => import('../pages/browse.vue'),
|
|
props: true,
|
|
meta: {
|
|
keepAlive: true,
|
|
requiresAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: '/credits/:paths+',
|
|
component: () => import('../pages/credits.vue'),
|
|
props: true,
|
|
meta: {
|
|
keepAlive: true,
|
|
requiresAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: '/person',
|
|
component: () => import('../pages/person.vue'),
|
|
props: true,
|
|
meta: {
|
|
requiresAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: '/media',
|
|
component: () => import('../pages/media.vue'),
|
|
meta: {
|
|
requiresAuth: true,
|
|
},
|
|
},
|
|
{
|
|
path: '/filemanager',
|
|
component: () => import('../pages/filemanager.vue'),
|
|
meta: {
|
|
requiresAuth: true,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
path: '/',
|
|
component: () => import('../layouts/blank.vue'),
|
|
children: [
|
|
{
|
|
path: 'login',
|
|
component: () => import('../pages/login.vue'),
|
|
},
|
|
{
|
|
path: '/:pathMatch(.*)*',
|
|
component: () => import('../pages/[...all].vue'),
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
|
|
// 路由导航守卫
|
|
router.beforeEach((to, from, next) => {
|
|
const isAuthenticated = store.state.auth.token !== null
|
|
|
|
if (to.meta.requiresAuth && !isAuthenticated) {
|
|
next('/login')
|
|
}
|
|
else {
|
|
startNProgress()
|
|
next()
|
|
}
|
|
})
|
|
|
|
router.afterEach(() => {
|
|
doneNProgress()
|
|
})
|
|
|
|
export default router
|