当前位置: 首页 > news >正文

若依 ruoyi-vue 获取上一页路由 获取返回上一页路径 登录后跳转其他页面 登录进入后跳转至动态路由的第一个路由

参考文章:若依框架登录后跳转其他页面&获取不同的菜单&登录进入后跳转至动态路由的第一个路由

需求:登录成功,默认跳转至后端返回的动态路由的第一个路由

隐藏首页可见

src/router/index.js
hidden: true,

在这里插入图片描述

保存第一个路由

src/store/modules/permission.js

将动态路由的第一个路由存到缓存中
在这里插入图片描述

import cache from '@/plugins/cache'let defaultPage='/index'//修改默认页面if (res.data[0] && res.data[0].children[0] && res.data[0].children[0].children[0]) {defaultPage = res.data[0].path + '/' + res.data[0].children[0].path + '/' + res.data[0].children[0].children[0].path} else if (res.data[0] && res.data[0].children[0]) {defaultPage = res.data[0].path + '/' + res.data[0].children[0].path}cache.session.set('defaultPage', defaultPage)
src/permission.js

存储上一路由,防止重复跳转
在这里插入图片描述

import cache from '@/plugins/cache'cache.session.set('prePath', from.path)

方案一,还保留首页,在首页自动跳转,改动地方太多了,可能漏改,我是首页,第一个路由都可跳转

src/views/index.vue
    gotoMenu() {const prePath = this.$cache.session.get('prePath')const defaultPage = this.$cache.session.get('defaultPage')let permi = checkPermi(['train:trainingrelease:list'])if (permi) {if (prePath !== '/train/training/trainingrelease') {this.$router.push({ path: '/train/training/trainingrelease' }).catch(() => {})}} else if (prePath !== defaultPage) {//如果上一页是默认页面,则不跳转到默认页面this.$router.push({ path: defaultPage }).catch(() => {})}},

方案二:不保留首页

目前我知道用到首页的地方,401、404、登录完成跳转

src/views/error/401和404
<template><div class="errPage-container"><el-button icon="arrow-left" class="pan-back-btn" @click="back">返回</el-button><el-row><el-col :span="12"><h1 class="text-jumbo text-ginormous">401错误!</h1><h2>您没有访问权限!</h2><h6>对不起,您没有访问权限,请不要进行非法操作!您可以返回主页面</h6><ul class="list-unstyled"><li class="link-type"><router-link :to="path">回首页</router-link></li></ul></el-col><el-col :span="12"><img :src="errGif" width="313" height="428" alt="Girl has dropped her ice cream."></el-col></el-row></div>
</template><script>
import errGif from '@/assets/401_images/401.gif'export default {name: 'Page401',data() {return {errGif: errGif + '?' + +new Date(),path: this.$cache.session.get('defaultPage')}},methods: {back() {if (this.$route.query.noGoBack) {this.$router.push({ path: this.path })} else {this.$router.go(-1)}}}
}
</script><style lang="scss" scoped>.errPage-container {width: 800px;max-width: 100%;margin: 100px auto;.pan-back-btn {background: #008489;color: #fff;border: none!important;}.pan-gif {margin: 0 auto;display: block;}.pan-img {display: block;margin: 0 auto;width: 100%;}.text-jumbo {font-size: 60px;font-weight: 700;color: #484848;}.list-unstyled {font-size: 14px;li {padding-bottom: 5px;}a {color: #008489;text-decoration: none;&:hover {text-decoration: underline;}}}}
</style>
        <router-link :to="path" class="bullshit__return-home">返回首页</router-link>
  data() {return {path: this.$cache.session.get('defaultPage')}},

登录页

      this.$store.dispatch('Login', this.loginForm).then(() => {this.loading = falselet defaultPage = this.$cache.session.get('defaultPage')this.$router.push({ path: this.redirect || defaultPage || '/index' }).catch(() => {})}).catch(() => {this.loading = false})

http://www.mrgr.cn/news/25428.html

相关文章:

  • Java设计模式之命令模式介绍和案例示范
  • Neo4j图数据库
  • C++学习笔记----6、内存管理(五)---- 智能指针(4)
  • Harmony Next 文件命令操作(发送、读取、媒体文件查询)
  • Python实现模糊逻辑算法
  • 基于ESP32S3的链接大语言模型对话模块
  • 算法刷题:300. 最长递增子序列、674. 最长连续递增序列、718. 最长重复子数组
  • 一文读懂多组学联合分析产品在医学领域的应用
  • 模拟实现计算器(switch函数实现与转移表实现)
  • 【Linux 19】线程概念
  • Unity基本操作
  • 【linux】一种基于虚拟串口的方式使两个应用通讯
  • 通信工程学习:什么是SDH同步数字体系
  • 大模型国产化算力方案
  • c++11——share_ptr的助手weak_ptr
  • 前端 + 接口请求实现 vue 动态路由
  • buck boost Ldo 经典模型的默写
  • 排序题目:一手顺子
  • 【办公】会议纪要模板
  • OJ 两两交换链表中的节点