redirect路由配置 vue_Vue 路由嵌套 二级路由和三级路由

1.main.js文件下二级路由和三级路由的引入,以及如何定义他们的路径path、名称name、调用组件component、默认展示组件redirect。

路由对象数组routes中存放着所有路由的路径和组件。在这里二级路由,以children数组的形式挂在一级路由对象里面,如下所示。

三级路由也挂在二级路由对象中的children数组里面。

Redirect挂在拥有二级路由的一级组件里表示,当我们打开这个一级路由时,默认展示redirect的路径值,也就是他其中一个二级路由。

import Vue from 'vue'import App from './App.vue'import VueRouter from 'vue-router'import Home from './components/Home'import Menu from './components/Menu'import Admin from './components/Admin'import About from './components/about/About'import Login from './components/Login'import Register from './components/Register'// 二级路由import Contact from './components/about/Contact'import Delivery from './components/about/Delivery'import History from './components/about/History'import OrderingGuide from './components/about/OrderingGuide'//三级路由import Phone from './components/about/contact/Phone'import PersonName from './components/about/contact/PersonName'
Vue.use(VueRouter)const routes = [{path:'/',name:"homeLink",component:Home},{path:'/menu',name:"menuLink",component:Menu},{path:'/admin',name:"adminLink",component:Admin},{path:'/about',name:"aboutLink",component:About,redirect:'/about/contact',children:[{path:'/about/contact',name:"contactLink",redirect:'/about/contact/personname',component:Contact,children:[{path:'/about/contact/phone',name:'phoneNumber',component:Phone},{path:'/about/contact/personname',name:'personName',component:PersonName},]},{path:'/about/delivery',name:"deliveryLink",component:Delivery},{path:'/about/history',name:"historyLink",component:History},{path:'/about/orderingGuide',name:"orderingGuideLink",component:OrderingGuide},]},{path:'/login',name:"loginLink",component:Login},{path:'/register',name:"registerLink",component:Register},{path:'*',redirect:'/'},];const router = new VueRouter({
routes,
mode:"history"})new Vue({
router,
el: '#app',render: h => h(App)})

2. 如上所示,contact、delivery、history、orderingGuide二级路由挂在一级路由about下。phone、personname三级路由挂在二级路由contact下面。

About组件代码如下:

eb40bab0b0524b21f74ad46240b5e8fa.png

1608bb248c582fe6d98ed72b706f183a.png

Contact组件代码如下:

83c41f7110f71c151714464cd5edc15f.png

编辑整理丨Mmm

0664556a7c3be16f60aef8cf4b0faa8f.png

5f1b17f3cc9b19208b54d841bb3c7e20.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值