vue之嵌套路由

关键词:路由

实际生活中的应用界面,通常由多层嵌套的组件组合而成。同样地,URL 中各段动态路径也按某种结构对应嵌套的各层组件

<div id="app">
  <p>
    <router-link to="/author/">贾岛</router-link>
  </p>
  <p>
    <router-link to="/author/title">忆江上吴处士</router-link>
  </p>
  <p>  
    <router-link to="/author/title/first">一</router-link>
    <router-link to="/author/title/secnd">二</router-link>
    <router-link to="/author/title/third">三</router-link>
    <router-link to="/author/title/forth">四</router-link>
  </p>
  <p>
    <router-link to="/author2/">张九龄</router-link>
  </p>
  <p>
    <router-link to="/author2/title">感遇</router-link>
  </p>
  <p>  
    <router-link to="/author2/title/first">一</router-link>
    <router-link to="/author2/title/secnd">二</router-link>
    <router-link to="/author2/title/third">三</router-link>
    <router-link to="/author2/title/forth">四</router-link>
  </p>
  <div>
    <router-view></router-view>  
  </div>
</div>

const Author = {
  template: `
    <div class="author">
      <h4>忆江上吴处士</h4>
      <router-view></router-view>
    </div>
  `
};
const Author2 = {
  template: `
    <div class="author2">
      <h4>感遇</h4>
      <router-view></router-view>
    </div>
  `
};
   const AutFirst = { template: '<div>闽国扬帆去,蟾蜍亏复圆。</div>' };
   const AutSecnd = { template: '<div>秋风吹渭水,落叶满长安。</div>' };
   const AutThird = { template: '<div>此地聚会夕,当时雷雨寒。</div>' };
   const AutForth = { template: '<div>兰桡殊未返,消息海云端。</div>' };

   const AutFirst2 = { template: '<div>兰叶春葳蕤,桂华秋皎洁。</div>' };
   const AutSecnd2 = { template: '<div>欣欣此生意,自尔为佳节。</div>' };
   const AutThird2 = { template: '<div>谁知林栖者,闻风坐相悦。</div>' };
   const AutForth2 = { template: '<div>草木有本心,何求美人折?</div>' };
   
   const router = new VueRouter({
     routes: [
       { path: '/author/:id', component: Author,
         children: [
           {
             path: 'first',
             component: AutFirst
           },
           {
             path: 'secnd',
             component: AutSecnd
           },
           {
             path: 'third',
             component: AutThird
           },
           {
             path: 'forth',
             component: AutForth
           },       
         ]
       },
       { path: '/author2/:id', component: Author2,
         children: [
           {
             path: 'first',
             component: AutFirst2
           },
           {
             path: 'secnd',
             component: AutSecnd2
           },
           {
             path: 'third',
             component: AutThird2
           },
           {
             path: 'forth',
             component: AutForth2
           },       
         ]
       }
     ],
   });

   new Vue({
    el:'#app',
     router
   });

想看一个真正的实例路由,请点击查看代码
https://github.com/ferrinte/meizu/blob/master/template/after_ser.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,188评论 19 139
  • 原文: https://github.com/ecomfe/spec/blob/master/javascript...
    zock阅读 8,688评论 2 36
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,671评论 25 709
  • vue2有着深度继承的路由插件,即:vue-router,其中文的API地址。 vue-router与其他的路由(...
    白水螺丝阅读 17,641评论 0 17
  • 后南老师告诉我们,运营分为用户运营、社区运营、渠道运营、产品运营、内容运营等。运营的核心价值是帮助资源高效提升,是...
    雪羽心风阅读 1,517评论 0 2

友情链接更多精彩内容