编写一段vue2嵌套路由的代码
时间: 2024-02-28 15:26:41 浏览: 149
好的,以下是嵌套路由的Vue2代码示例:
```
import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home'
import About from '@/components/About'
import Contact from '@/components/Contact'
import Services from '@/components/Services'
import ServiceDetail from '@/components/ServiceDetail'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/about',
name: 'About',
component: About
},
{
path: '/contact',
name: 'Contact',
component: Contact
},
{
path: '/services',
name: 'Services',
component: Services,
children: [
{
path: ':id',
name: 'ServiceDetail',
component: ServiceDetail
}
]
}
]
})
```
这段代码定义了四个路由:Home、About、Contact和Services。Services路由下还有一个子路由ServiceDetail,用于显示服务详情。
阅读全文
相关推荐


















