路由配置

// router/index.js
import Vue from 'vue'
import Router from 'vue-router'

// 引入组件
import home from 'components/home'
import detail from 'components/detail'
// 或者使用路由懒加载
const home = () => import('components/home')
const detail = () => import('components/detail')

Vue.use(Router)

// 配置
export default new Router({
    // mode: 'history', // 默认 hash 模式
    'linkActiveClass': 'active', // 路由对应class
    routes: [
        {
            { path: '/', component: home }, // 根路由
            { path: '/home', name: 'home', component: home }, // home路由
            { path: '/detail/:id', name: 'detail', component: detail }, // detail路由
            { path: '*', redirect: '/home' }, // 找不到路由时
        }
    ]
})

Last updated