Comments (8)
把 permission.js
的代码发一下
from vue-admin-template.
这部分我应该没怎么改动
import { LoadingBar } from 'view-design'
import createRoutes from '@/utils/createRoutes'
import router from './router'
import store from './store'
import { getDocumentTitle, resetTokenAndClearUser } from './utils'
// 是否有菜单数据
let hasMenus = false
router.beforeEach(async (to, from, next) => {
document.title = getDocumentTitle(to.meta.title)
LoadingBar.start()
if (localStorage.getItem('token')) {
if (to.path === '/login') {
next({ path: '/' })
} else if (hasMenus) {
next()
} else {
try {
const routes = createRoutes(store.state.menuItems)
router.addRoutes(routes)
hasMenus = true
next({ path: to.path || '/' })
} catch (error) {
resetTokenAndClearUser()
next(/login?redirect=${to.path}
)
}
}
} else {
hasMenus = false
if (to.path === '/login') {
next()
} else {
next(/login?redirect=${to.path}
)
}
}
})
router.afterEach(() => {
LoadingBar.finish()
})
from vue-admin-template.
发代码的时候把代码放在两个 ``` 中间。
```
test
```
类似这样
from vue-admin-template.
不好意思,比较少提issue,不大清楚,我比较了下你这边的,应该只是我把import createroute提前了,因为我这边如果不提前他就会报错
import { LoadingBar } from 'view-design'
import createRoutes from '@/utils/createRoutes'
import router from './router'
import store from './store'
import { getDocumentTitle, resetTokenAndClearUser } from './utils'
// 是否有菜单数据
let hasMenus = false
router.beforeEach(async (to, from, next) => {
document.title = getDocumentTitle(to.meta.title)
LoadingBar.start()
if (localStorage.getItem('token')) {
if (to.path === '/login') {
next({ path: '/' })
} else if (hasMenus) {
next()
} else {
try {
const routes = createRoutes(store.state.menuItems)
router.addRoutes(routes)
hasMenus = true
next({ path: to.path || '/' })
} catch (error) {
resetTokenAndClearUser()
next(/login?redirect=${to.path})
}
}
} else {
hasMenus = false
if (to.path === '/login') {
next()
} else {
next(/login?redirect=${to.path})
}
}
})
router.afterEach(() => {
LoadingBar.finish()
})
from vue-admin-template.
这个看着没问题,看一下路由文件,估计是重定向导致的。
from vue-admin-template.
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
const commonRoutes = [
{
path: '/login',
name: 'login',
meta: { title: '登录' },
component: () => import('../components/Login.vue'),
},
{
path: '/404',
name: '404',
meta: { title: '404' },
component: () => import('../components/404.vue'),
},
{ path: '/', redirect: '/home' },
]
// 本地所有的页面 需要配合后台返回的数据生成页面
export const asyncRoutes = {
home: {
path: '/home',
name: 'home',
meta: { title: '主页' },
component: () => import('../views/Home.vue'),
},
messagelist: {
path: '/messagelist',
name: 'messagelist',
meta: { title: '信息展示' },
component: () => import('../views/messagelist.vue'),
},
}
const createRouter = () => new Router({
routes: commonRoutes,
})
const router = createRouter()
export function resetRouter() {
const newRouter = createRouter()
router.matcher = newRouter.matcher
}
export default router
from vue-admin-template.
补充下store信息
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
// 左侧菜单栏数据
menuItems: [
{
name: 'home',
text: '主页',
size: 18,
type: 'md-home',
},
{
size: 18,
text: '主机信息',
type: 'md-desktop',
children: [
{
size: 18,
type: 'ios-grid',
name: 'messagelist',
text: '信息展示',
},
],
},
],
},
mutations: {
setMenus(state, items) {
state.menuItems = [...items]
},
},
})
from vue-admin-template.
{ path: '/', redirect: '/home' },
这行代码有问题,把它放到异步路由里。
from vue-admin-template.
Related Issues (20)
- 页面跳转到详情页 HOT 3
- 权限控制 HOT 1
- 想找个前端配合个完整的系统 HOT 4
- 开发环境npm run serve可以跨域访问,正式环境打包npm run build后不能跨域访问 HOT 3
- Sidebar 组件 内部 嵌套dialog 出现样式异常, fixed 定位层级嵌套 HOT 10
- 跳到一个单独的路由页面,是在哪里设置的? HOT 1
- 注销后登录报错 HOT 1
- 请教一下你用的git message规范和changelog工具 HOT 3
- 希望能同步到gitee上 HOT 2
- 二级路由的组件如何加载? HOT 1
- 如何发送ajax请求 HOT 1
- vue 发送ajax到 springboot HOT 2
- ajax穿过的数据太多,页面无法滚动 HOT 1
- 左侧边栏的图标怎么设置 HOT 1
- 你好,tab太多显示不下后,新开tab怎么滚动 HOT 1
- 关闭eslint HOT 1
- 项目如何嵌入该项目其他.vue文件 HOT 1
- 怎么在请求头中放数据 HOT 1
- 怎么携带cookies
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-admin-template.