当前位置: 首页 > 知识库问答 >
问题:

vue.js - Element UI el-menu 跳转错误:路径变为 /message/detail/index 如何解决?

周飞
2024-08-23

我的页面是三级嵌套路由,结构类似于 /message/detail/0。
页面的菜单使用了element-ui的el-menu
但我点击菜单的选项返回首页的时候,页面路径变成了/message/detail/index。

这个是路由配置的JS:

const routes = [
  {
    path: '/',
    name: 'layout',
    redirect:'/index',
    component: () => import('../views/Layout.vue'),
    children: [
      {
        path: 'index',
        component:() => import('../views/index/index.vue')
      },
      {
        path:'message',
        component:() => import('../views/message/message.vue'),
        children:[
          {
            path:'detail/:id',
            component:() => import('../views/message/messageDetail.vue')
          }
        ]
      }
    ]
  }
]

image.png
image.png

请问我该如何解决这个问题,希望从 /message/detail/0 页面直接跳转到 /index。

补充问题:
使用的是el-menu默认的方法
在el-menu标签设置router,给每个el-menu-item设置index
代码如下:

        <el-menu
          :default-active="active"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          :collapse="isCollapse"
          router
        >
          <el-menu-item index="index">
            <i class="el-icon-menu"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span slot="title">信息管理</span>
            </template>
            <el-menu-item-group>
              <!-- <span slot="title">分组一</span> -->
              <el-menu-item index="newslist">新闻管理</el-menu-item>
              <el-menu-item index="activelist">活动管理</el-menu-item>
              <el-menu-item index="memberlist">成员管理</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span slot="title">审核平台</span>
            </template>
            <el-menu-item-group>
              <!-- <span slot="title">分组一</span> -->
              <el-menu-item index="platform">审核中心</el-menu-item>
              <el-menu-item index="workbench">工作台</el-menu-item>
              <el-menu-item index="lastaudit">历史数据</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-menu-item index="message">
            <i class="el-icon-message"></i>
            <span slot="title">站内通知</span>
          </el-menu-item>
          <el-menu-item index="calendar">
            <i class="el-icon-date"></i>
            <span slot="title">日程</span>
          </el-menu-item>
          <el-menu-item index="setting">
            <i class="el-icon-setting"></i>
            <span slot="title">设置</span>
          </el-menu-item>
        </el-menu>

js代码:

<script>
export default {
  name: "DmindexManagementLayout",

  data() {
    return {
      isCollapse: false,
      active: "index",
    };
  },
  watch: {
    $route: {
      handler(newval, oldval) {
        // console.log(newval); //新路由信息
        this.active = newval.name
      },
      // 深度观察监听
      deep: true,
      immediate: true,
    },
  },
  created(){},
  mounted() {},

  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
  },
};
</script>

共有2个答案

解浩渺
2024-08-23

把message这级路由拿出来和/级路由同级,而不是在chidlren里试试;

施慈
2024-08-23

看看你返回首页的代码是怎么写的

 类似资料:
  • 错误:JAVA_HOME设置为无效目录:/Library/JAVA/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/HOME 请在您的环境中设置JAVA_HOME变量,以匹配您的JAVA安装位置。 更新后,我得到了这种类型的错误。我已经重新安装了jdk,但同样error.Please帮助

  • 如何自动跳转项目的首页 目前得手动输入xxx.com/admin/login才能跳转到login页面,如何在输入xxx.com/admin的情况下自动跳转login页面呢 src/router/index.js config/index.js

  • 问题: 前端如何跳转页面路径 ? 我尝试使用了路由的语法, 但是没有跳转

  • 我的应用程序使用spring boot版本2.5.0和spring cloud starter netflix zuul 2.2.8。释放 在最新的spring boot版本2.5.0中,getErrorPath()API从ErrorController中删除,但最新的spring cloud starter netflix zuul 2.2.8。RELEASE仍调用此API并导致此错误 有人遇到

  • 问题内容: 我收到此错误: 我正在使用Tomcat 6作为Web服务器。我有两个HTTPS Web应用程序安装在不同端口上但在同一台机器上的不同Tomcat上。说App1(port 8443)和 App2(port 443)。App1连接到App2。当App1连接到App2我得到以上错误。我知道这是一个非常常见的错误,因此在不同的论坛和站点上遇到了许多解决方案。我在server.xml两个Tomc

  • 问题内容: 我在ttf文件中有一种字体,想要生成文本转换为路径的SVG。我不需要图像(因此使用imagettftext或Image Magick字体渲染功能是不够的),我需要可以放大和缩小的形状,我想丢失有关所用字体的信息,并且不想在其中引用它SVG文件(因此此处不能使用字体声明)。可能吗? 问题答案: 我创建了自己的类来处理SVG字体文件并将文本转换为字形。使用示例: 结果示例: 我班的代码:

  • 各位大佬,我想问个关于vscode ctrl+鼠标左键跳转的问题 在vue项目中需要配置@符号用来表示/src文件,然后写大型项目的时候我想用ctrl加左键进行快捷跳转,但是一直报错打不开怎么办? 我从网上找了好久无果,包括配置jsconfig.json,安装什么"别名路径跳转插件"都不行,而且我的鼠标左键一点击就默认选中整个链接,而不是部分,鼠标左键移动到跳转链接一定会把@符号给带进去,所以一直

  • 使用指南 - 统计设置 - 转化设置 - 转化路径如何设置 在设置页面转化时,选择开启转化路径。 点击开启后界面如图所示: 若到达目标页面需要多个步骤,可点击①位置增加步骤。 若该步骤可以有多个页面,经过其中任意一个页面都算作经过该步骤,可以点击②位置增添该步骤的网址,网址内容也支持使用通配符。 系统默认只要到达目标页面都会计为转化。若我们认为必须经过某个步骤后到达目标页面的行为才可以计为转化,可