1.嵌套路由的使用场景是什么呢?
大家都知道选项卡,在选项卡中,顶部有数个导航栏,中间的主体显示的是内容;这个时候,整个页面是一个路由,然后点击选项卡切换不同的路由来展示不同的内容,这个时候就是路由中嵌套路由。
2.具体是怎么实现的?
① 为了演示,我们现在view文件夹下新建一个title1.vue
和title2.vue
用来存放不同的内容


② 现在我们在router
》 index.js
中将这上面两个新建的组件引入进来并填写路径,这里的Title1
和Title2
是作为test.vue
页面的子路由,所以要写在children
属性下

这里需要提个醒的就是填写children
子路由的path
不要加/
③ 然后我们再去到test.vue中敲:
在这里提个醒,在to
后面写路由路径的时候,一定到带上绝对路径,也就是要把test
这个父路由路径写进去"/test/title1"

④ 最后我们进入浏览器点击不同的标题就可以看到不同内容的展示


网友评论