当前位置:Gxlcms > JavaScript > vue.js路由显示设置的方法介绍

vue.js路由显示设置的方法介绍

时间:2021-07-01 10:21:17 帮助过:7人阅读

本篇文章给大家带来的内容是关于vue.js路由显示设置的方法介绍,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

①设置 path 为 ‘/’

  1. const router= new VueRouter({
  2. routes:[
  3. {path:'/',name:'home',component:Home}, //页面第一显示的组件
  4. {path:'/menu',name:'menu',component:Menu},
  5. {path:'*',redirect:'/'}
  6. ],
  7. mode:"history"
  8. });

②设置 redirect 的值(适用于 二级路由)

  1. const router= new VueRouter({
  2. routes:[
  3. {path:'/',name:'home',component:Home},
  4. {path:'/about',name:'about',component:About,redirect:{name:'contactLink'},children:[ //二级路由
  5. {path:'/about/contact',name:'contactLink',component:Contact},
  6. {path:'/history',name:'historyLink',component:History},
  7. ]},
  8. {path:'*',redirect:'/'}
  9. ],
  10. mode:"history"
  11. });

相关推荐:

vue.js中二级路由和三级路由的代码解析

Vue.js路由器的使用方法总结(附代码)

以上就是vue.js路由显示设置的方法介绍的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行