import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../views/Layout.vue'
import Login from '../views/Login.vue'
import Register from '../views/Register.vue'
Vue.use(VueRouter)
// 定义路由
const routes = [
{
path: '/',
name: 'home',
component: HomeView,
// redirect 表示要被重定向的新地址
redirect: '/layout'
},
{
path: '/layout',
name: 'layout',
component: Layout,
// 通过children属性定义子路由,是数组嵌套字典的形式
children: [
// 相对路径写法
{ path: "login", component: Login },
{ path: "register", component: Register },
// 绝对路径写法
// { path: "/layout/login", component: Login },
// { path: "/layout/register", component: Register },
]
},
]
const router = new VueRouter({
routes
})
export default router
评论