Vue路由

父组件

  • main.html

  
//插入路由
  • main.js
new Vue({
  el: '#app',
  router,           //注入路由
  store,
  template: '',
  components: { App }
})
  • router/index.js
//1.使用Vue-router
import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

let routes = [{
    path:'/',
    component:require('../components/member.vue').default     //子路由
},
{
    path:'/address',
    component:require('../components/address.vue').default,
    //嵌套路由
    children:[{
        path:'',
        redirect:'all'  //重定向

    },{
        path:'all',
        name:'all',
        component:require("../components/all.vue").default    //子路由

    },{
        path:'form',
        name:'form',
        component:require("../components/form.vue").default
    }]
}]

//2.创建router实例
let router = new Router({
    routes
})

export default router

你可能感兴趣的:(Vue路由)