import Vue from 'vue' import VueRouter from 'vue-router' import HomeView from '../views/HomeView.vue' Vue.use(VueRouter) const routes = [ { path: '/', name: 'home', component: HomeView }, { 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/AboutView.vue') }, { // path 代表路由的路径 会显示在地址栏中 path:"/mypage", // name 代表路由的名称 name:"mypage", // component 代表路由的组件 当前要显示的页面 component:() => import("../views/MyPage.vue"), // alias 别名 alias:'/my', // children 代表子路由 children:[ { path:'/mypage/childone', name:'childone', component:() => import("../views/ChildOne.vue") }, { path:'/mypage/childtwo', name:"childtwo", component:() => import("../views/ChildTwo.vue") }, { path:'/mypage/childthree/:username/:age', name:'childthree', component:() => import("../views/ChildThree.vue") } ] },{ path:'/backhome', redirect:'/' },{ path:"/gochildthree/:username/:age", redirect:"/mypage/childthree/:username/:age" } ] const router = new VueRouter({ routes }) export default router