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",
            },
        },
    ],
},
相关推荐
前端Hardy15 分钟前
前端必看!LocalStorage这么用,再也不踩坑(多框架通用,直接复制)
前端·javascript·面试
前端Hardy16 分钟前
前端必看!前端路由守卫这么写,再也不担心权限混乱(Vue/React通用)
前端·javascript·面试
Lee川37 分钟前
从零构建现代化登录界面:React + Tailwind CSS 前端工程实践
前端·react.js
Awu122737 分钟前
⚡精通 Claude 第 1 课:掌握 Slash Commands
前端·人工智能·ai编程
竹林81838 分钟前
从ethers.js迁移到Viem:我在重构DeFi前端时踩过的那些坑
前端·javascript
码云之上42 分钟前
上下文工程实战:解决多轮对话中的"上下文腐烂"问题
前端·node.js·agent
小小弯_Shelby44 分钟前
webpack优化:Vue配置compression-webpack-plugin实现gzip压缩
前端·vue.js·webpack
小村儿1 小时前
连载04-CLAUDE.md ---一起吃透 Claude Code,告别 AI coding 迷茫
前端·后端·ai编程
攀登的牵牛花1 小时前
我把 Gemma4:26b 装进 M1 Pro 后,才看清 AI 编程最贵的不是模型费,而是工作流
前端·agent
前端郭德纲1 小时前
JavaScript Object.freeze() 详解
开发语言·javascript·ecmascript