使用 children 属性实现路由嵌套

   <div >register</router-link>
        <router-view></router-view>
      </div>`
    });
 
    // 子路由中的 login 组件
    const login = Vue.extend({
      template: '<div>登录组件</div>'
    });
 
    // 子路由中的 register 组件
    const register = Vue.extend({
      template: '<div>注册组件</div>'
    });
 
    // 路由实例
    var router = new VueRouter({
      routes: [
        { path: '/', redirect: '/account/login' }, // 使用 redirect 实现路由重定向
        {
          path: '/account',
          component: account,
          children: [ // 通过 children 数组属性,来实现路由的嵌套
            { path: 'login', component: login }, // 注意,子路由的开头位置,不要加 / 路径符
            { path: 'register', component: register }
          ]
        }
      ]
    });
 
    // 创建 Vue 实例,得到 ViewModel
    var vm = new Vue({
      el: '#app',
      data: {},
      methods: {},
      components: {
        account
      },
      router: router
    });
  </script>
 

 

相关文章:

  • 2021-06-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2021-03-30
  • 2022-02-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-04-15
  • 2022-12-23
  • 2021-06-09
  • 2021-03-31
  • 2021-11-28
相关资源
相似解决方案