Vue Router - 记录一下 2 种路由写法

记录一下 2 种路由写法

  1. 如下写法,可以通过 /test/myTest/test 访问到 MyTest,更推荐此写法
js 复制代码
{
    name: "Test",
    path: "/test",
    component: "Layout",
    redirect: "/test/myTest",
    meta: {
        noCache: true,
        title: "测试",
        icon: "tool",
        link: null,
    },
    children: [
        {
            path: "myTest",
            component: "test/myTest/index",
            name: "MyTest",
            meta: {
                noCache: true,
                title: "我的测试",
                icon: "tool",
            },
        },
    ],
},
  1. 如下写法,可以通过 /test/myTest 访问到 MyTest,不能通过 /test 访问到 MyTest(404)
js 复制代码
{
    name: "Test",
    path: "",
    component: "Layout",
    redirect: "/test/myTest",
    meta: {
        noCache: true,
        title: "测试",
        icon: "tool",
        link: null,
    },
    children: [
        {
            path: "/test/myTest",
            component: "test/myTest/index",
            name: "MyTest",
            meta: {
                noCache: true,
                title: "我的测试",
                icon: "tool",
            },
        },
    ],
},
相关推荐
油丶酸萝卜别吃3 小时前
utils.js 说明文档
开发语言·javascript·ecmascript
zyplayer-doc5 小时前
VuePress类静态文档站和动态知识库怎么选:两种技术路线的适用场景
javascript·人工智能·后端·安全·智能手机
紫禁玄科6 小时前
Shai-Hulud:npm生态的自我复制蠕虫风暴
前端·npm·node.js
东风破_7 小时前
后端API没写好,前端难道干等着吗?
前端
用户938515635077 小时前
从前后端分离到前端接口工程:React + MockJS + Vite 解析
前端·后端·全栈
用户938515635077 小时前
从零在浏览器里跑 DeepSeek-R1:WebGPU + Transformers.js 全链路实战(三)
前端·react.js·typescript
excel7 小时前
当前端行情变差,我们为什么还要坚持?
前端
鸿是江边鸟,曾是心上人8 小时前
快速搭建HTTPS本地开发环境
前端
To_OC8 小时前
写了 5 个表单 Demo 后,我终于彻底搞懂了 React 受控与非受控组件
前端·react.js·前端框架
Sterting9 小时前
第9课 Vue Router 路由
前端·vue.js