12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import * as vueRouter from 'vue-router'
- import baseData from "./modules/base";
- import {getToken} from '~src/api/util/auth'
- import {getRouterData} from './routers'
- import NProgress from "nprogress";
- import "~src/styles/app/nprogress.scss";
- import config from "~src/config";
- //设置路由数据
- const router = vueRouter.createRouter({
- history: vueRouter.createWebHashHistory(),
- routes: baseData
- });
- //路由拦截
- router.beforeResolve(async (to) => {
- NProgress.start();
- const token = getToken()
- if (to.path === '/login') {
- return true
- } else if (to.path === '/auth') {
- return true
- } else if (!token) {
- return '/login'
- } else {
- return true
- /*const res = await getRouterData(to.name)
- if (res) {
- return true
- } else {
- return '/login'
- }*/
- }
- })
- router.afterEach((to) => {
- let pageTitle = to.meta['title'], title = config.title;
- if (to.path !== "/") {
- window.document.title = pageTitle?`${pageTitle} - ${title}`:title;
- } else {
- window.document.title = title;
- }
- window.scrollTo(0, 0)
- NProgress.done();
- })
- export function setupRouter(app){
- app.use(router)
- return router
- }
- export default router;
|