嵌套路由实现方法分析

前面讲过了vue2路由基本用法,一般应用中的路由方式不会像上述例子那么简单,往往会出现二级导航这种情况。这时就需要使用嵌套路由这种写法。

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>routerTest1</title> <c:import url="importFile.jsp"></c:import> </head> <body> <div> <nav> <div> <div> <a href="#" >Brand</a> </div> <div> <ul> <%--定义跳转的路径--%> <li> <router-link to="/home">Home</router-link></li> <li> <router-link to="/list">List</router-link></li> </ul> </div> </div> </nav> <div> <!—路由切换组件template 插入的位置 --> <router-view></router-view> </div> </div> <script type="x-template"> <div> <h1> this is home page </h1> <div> <ul > <li> <router-link to="/home/lists">List</router-link> </li> <li> <router-link to="/home/detail">Detail</router-link> </li> </ul> </div> <router-view></router-view> </div> </script> <script> /* * var Home = Vue.extend({ template:'<h1> this is home page </h1>', }) * */ /*使用Javascript模板定义组件*/ var Home = Vue.extend({ template:'#modalTel' }) /*创建路由器实例*/ const router = new VueRouter({ routes:[ { path: 'https://www.jb51.net/', redirect: '/home' }, { path:'/home', component:Home, /*嵌套下的路由(子路由)*/ children:[ { path:'/home/lists', component:{ template:'<h1> this is lists pages</h1>' }, }, { path:'/home/detail', component:{ template:'<h1> this is detail pages</h1>' }, } ] }, { path:'/list', component:{ /*显示路由的属性*/ template:'<h1> this is list page----{{$route.path}}</h1>' } } ] }); const app = new Vue({ router:router }).$mount('#app') </script> </body> </html>

嵌套路由实现方法分析

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/d42f50a785f458ecb11ba1dbcd706e89.html