欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

路由嵌套

程序员文章站 2022-06-02 20:15:01
...

1.嵌套到路由about页面上,

  1. 指定路由路径
<router-link to="/about/new">新闻</router-link>
  1. 指定路由展示
<router-view></router-view>
//about
<template>
    <div>
        <h2>关于</h2>
        <router-link to="/about/new">新闻</router-link>
        <router-link to="/about/sport">运动</router-link>
        <router-view></router-view>
    </div>
</template>

<script>
    export default {
        name: "About"
    }
</script>

<style scoped>

</style>

2.配置路由,在该嵌套路由下用children再配置子路路径

//index.js
{
        path: '/about',
        component: About,
        children: [
            {
                path: 'new',
                component: New
            },
            {
                path: 'sport',
                component: Sport
            }
        ]
    },
相关标签: 笔记