198 lines
5.6 KiB
JavaScript
198 lines
5.6 KiB
JavaScript
import Vue from 'vue'
|
|
import VueRouter from 'vue-router'
|
|
import index from '../views/Index.vue'
|
|
import home from "@/components/home/HomePage.vue";
|
|
import news from "@/components/hotNews/HotNews.vue";
|
|
import navDetail from "@/components/detail/NavDetail.vue";
|
|
import notFound from "@/components/notFound/NotFound.vue";
|
|
import settings from "@/views/Settings.vue";
|
|
import appearanceSettings from "@/components/setting/system/AppearanceSettings.vue";
|
|
import informationSettings from "@/components/setting/system/InformationSettings.vue";
|
|
import functionSettings from "@/components/setting/system/FunctionSettings.vue";
|
|
import systemSettings from "@/components/setting/system/SystemSettings.vue";
|
|
import websiteManage from "@/components/setting/website/websiteManage.vue";
|
|
import myNav from "@/components/myNav/MyNav.vue";
|
|
import personalHomePage from "@/components/setting/home/PersonalHomePage.vue";
|
|
import onSiteSetting from "@/components/setting/onsite/OnSiteSetting.vue";
|
|
import baseSettings from "@/components/setting/onsite/BaseSettings.vue";
|
|
import importExport from "@/components/setting/importExport/ImportExport.vue";
|
|
import categoryManage from "@/components/setting/category/CategoryManage.vue";
|
|
import bannerManage from "@/components/setting/banner/BannerManage.vue";
|
|
import userManage from "@/components/setting/user/UserManage.vue";
|
|
import noticeManage from "@/components/setting/notice/NoticeManage.vue";
|
|
import attachmentManage from "@/components/setting/attachment/AttachmentManage.vue";
|
|
|
|
const originalPush = VueRouter.prototype.push
|
|
VueRouter.prototype.push = function push(location) {
|
|
return originalPush.call(this, location).catch(err => err)
|
|
}
|
|
Vue.use(VueRouter)
|
|
|
|
const routes = [
|
|
{
|
|
path: '/',
|
|
redirect: '/index'
|
|
},
|
|
{
|
|
path: '/index',
|
|
redirect: '/home',
|
|
name: 'index',
|
|
component: index,
|
|
children: [
|
|
{
|
|
path: '/home',
|
|
name: 'home',
|
|
component: home
|
|
},
|
|
{
|
|
path: '/news',
|
|
name: 'news',
|
|
component: news
|
|
}, {
|
|
path: '/nav',
|
|
name: 'nav',
|
|
component: navDetail
|
|
},
|
|
{
|
|
path: '/myNav',
|
|
name: 'myNav',
|
|
component: myNav
|
|
}
|
|
],
|
|
},
|
|
{
|
|
path: '/settings',
|
|
redirect: '/admin',
|
|
name: '/settings',
|
|
component: settings,
|
|
|
|
children: [
|
|
{
|
|
path: '/admin',
|
|
name: '/admin',
|
|
component: personalHomePage,
|
|
},
|
|
{
|
|
path: '/system',
|
|
name: '/system',
|
|
redirect: '/appearance',
|
|
component: systemSettings,
|
|
children: [
|
|
{
|
|
path: '/appearance',
|
|
name: '/appearance',
|
|
component: appearanceSettings,
|
|
|
|
|
|
},
|
|
{
|
|
path: '/information',
|
|
name: '/information',
|
|
component: informationSettings,
|
|
|
|
|
|
},
|
|
{
|
|
path: '/function',
|
|
name: '/function',
|
|
component: functionSettings,
|
|
|
|
}
|
|
]
|
|
},
|
|
{
|
|
path: '/website',
|
|
name: '/website',
|
|
component: websiteManage,
|
|
},
|
|
{
|
|
path: '/onSite',
|
|
name: '/onSite',
|
|
redirect: '/baseSettings',
|
|
component: onSiteSetting,
|
|
children: [
|
|
{
|
|
path: '/baseSettings',
|
|
name: '/baseSettings',
|
|
component: baseSettings,
|
|
|
|
|
|
},
|
|
|
|
]
|
|
},
|
|
{
|
|
path: '/category',
|
|
name: '/category',
|
|
component: categoryManage,
|
|
},
|
|
{
|
|
path: '/banner',
|
|
name: '/banner',
|
|
component: bannerManage,
|
|
},
|
|
{
|
|
path: '/user',
|
|
name: '/user',
|
|
component: userManage,
|
|
},
|
|
{
|
|
path: '/notice',
|
|
name: '/notice',
|
|
component: noticeManage,
|
|
},
|
|
{
|
|
path: '/attachment',
|
|
name: '/attachment',
|
|
component: attachmentManage,
|
|
},
|
|
{
|
|
path: '/importExport',
|
|
name: '/importExport',
|
|
component: importExport,
|
|
},
|
|
|
|
],
|
|
},
|
|
|
|
|
|
{
|
|
path: '/404',
|
|
name: 'NoPage404',
|
|
component: notFound,
|
|
hidden: true
|
|
},
|
|
{
|
|
path: '/:pathMatch(.*)',
|
|
redirect: '/404',
|
|
hidden: true
|
|
},
|
|
|
|
|
|
]
|
|
|
|
const router = new VueRouter({
|
|
mode: 'history',
|
|
routes
|
|
})
|
|
// // 导航守卫:使用 router.beforeEach 注册一个全局前置守卫,判断用户是否登陆
|
|
router.beforeEach((to, from, next) => {
|
|
if (to.path === '/home' || to.path === '/news') {
|
|
next();
|
|
} else {
|
|
let token = localStorage.getItem('Authorization');
|
|
if (token === null || token === '' || token === undefined) {
|
|
next('/home');
|
|
Vue.prototype.$notify.error({
|
|
title: '权限不够',
|
|
message: "请先登录!",
|
|
offset: 0
|
|
});
|
|
} else {
|
|
next();
|
|
}
|
|
}
|
|
});
|
|
|
|
export default router
|