vue
  • Vue基础
  • 生命周期
  • 实用技巧
  • 相关资料
  • 组件通讯
    • 父传子
    • 子传父
    • eventBus
    • Vuex
  • 路由
    • 路由配置
    • 路由使用
  • 封装组件
    • 自定义组件上使用v-model监听
    • js调用modal组件
  • 插件
    • 图表
    • vue-awesome-swiper
Powered by GitBook
On this page
  1. 路由

路由配置

PreviousVuexNext路由使用

Last updated 6 years ago

CtrlK
// 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' }, // 找不到路由时
}
]
})