直接贴代码
这是一个简单例子权限路由是Table
注意最后那个{ path: '*', redirect: '/404', hidden: true }
这个不能一开始就导入路由,要放到addRoutes里面.
如果一开始就导入的话,刷新页面,router会找不到动态路由Table组件,因为这个时候并没有添加进来,router会直接重定向404
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Table from "../views/Table";
Vue.use(VueRouter)
const routes = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/about',
name: 'About',
// 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: "about" */ '../views/About.vue')
},
// {
// path: '/table',
// name: 'Table',
// // route level code-splitting
// // this generates a separate