vue 路由(router)导入两种方式

vue 路由(router)导入两种方式

第一种:

import Home from '../views/Home.vue'

Vue.use(VueRouter)

  const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  }
]

第二种:

注意箭头 ()=> 一定要有的!

import Home from '../views/Home.vue'

Vue.use(VueRouter)

  const routes = [
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue')
  }
]

重定向:

import Home from '../views/Home.vue'

Vue.use(VueRouter)

  const routes = [
    {
      path: '/',
      redirect: 'login'
    }
]

你可能感兴趣的:(vue)