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.

80 lines
2.4 KiB

import Vue from 'vue';
import VueRouter from 'vue-router';
import store from '../store';
import HomeView from '../views/HomeView.vue';
// import UserPosts from '../views/UserPosts.vue';
// import Franchise from '../views/Franchise.vue'
3 months ago
Vue.use(VueRouter)
const whiteSlideList = ['/','/ui'];//侧边导航白名单
const whiteHeaderList = ['/','/ui','/register'];//头部导航白名单
const whiteFooterList = ['/','/ui'];//底部白名单
3 months ago
const routes = [
{
path: '/',
name: '首页',
component: HomeView,
// component: Franchise
3 months ago
},
{
path: '/register',
name: 'register',
3 months ago
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "register" */ '../views/Register.vue'),
children: [ // 这是子路由的定义开始
// {
// path: '', // 当访问 /user 时,默认加载 UserProfile 组件
// name: 'register',
// component: Register
// },
// {
// path: 'posts', // 当访问 /user/posts 时,加载 UserPosts 组件
// name: 'UserPosts',
// component: UserPosts,
// }
]
},
{
path: '/ui',
name: 'ui组件',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "ui" */ '../views/elementGroups.vue')
},
{
path: '/franchise',
name: '加盟',
component: () => import(/* webpackChunkName: "franchise" */ '../views/Franchise.vue')
},
3 months ago
]
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
router.beforeEach((to, from, next) => {
console.log(to.path,'to.path-----');
if (whiteSlideList.includes(to.path)) {
store.commit('SET_SIDEBAR', true); // 登录页面不显示侧边栏
} else {
store.commit('SET_SIDEBAR', false); // 其他页面显示侧边栏
}
if (whiteFooterList.includes(to.path)) {
store.commit('SET_FOOTER', true); // 登录页面不显示侧边栏
} else {
store.commit('SET_FOOTER', false); // 其他页面显示侧边栏
}
if (whiteHeaderList.includes(to.path)) {
store.commit('SET_HEADER', true); // 登录页面不显示侧边栏
} else {
store.commit('SET_HEADER', false); // 其他页面显示侧边栏
}
next();
});
3 months ago
export default router