RuoYi若依框架去除首页

  1. ruoyi-ui\src\permission.js修改router.beforeEach代码
router.beforeEach((to, from, next) => {
  NProgress.start()
  if (getToken()) {
    to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
      if (store.getters.roles.length === 0) {
        store.dispatch('GetInfo').then(res => {
          const roles = res.roles
          store.dispatch('GenerateRoutes', { roles }).then(accessRoutes => {
            router.addRoutes(accessRoutes) 
            if (to.fullPath == '/') {
              var heardPath=accessRoutes[0].path.split("/")[1]==''?"":accessRoutes[0].path;
              let pathIndex = ''
              pathIndex = heardPath + '/' + accessRoutes[0].children[0].path
              next({ path: pathIndex, replace: true }) 
            } else {
              next({ ...to, replace: true }) 
            }
          })
        }).catch(err => {
            store.dispatch('LogOut').then(() => {
              Message.error(err)
              location.href = '/login';
            })
          })
      } else {
        next()
      }
  } else {
    if (whiteList.indexOf(to.path) !== -1) {
      next()
    } else {
      next(`/login?redirect=${encodeURIComponent(to.fullPath)}`) 
      NProgress.done()
    }
  }
})
  1. ruoyi-ui/src/store/modules/permission.js修改代码
const permission = {
  state: {
    routes: [],
    addRoutes: [],
    defaultRoutes: [],
    topbarRouters: [],
    sidebarRouters: [],
    //修改默认页面
    indexPage:''
  },
  mutations: {
    SET_ROUTES: (state, routes) => {
      state.addRoutes = routes
      state.routes = constantRoutes.concat(routes)
    },
    SET_DEFAULT_ROUTES: (state, routes) => {
      state.defaultRoutes = constantRoutes.concat(routes)
    },
    SET_TOPBAR_ROUTES: (state, routes) => {
      state.topbarRouters = routes
    },
    SET_SIDEBAR_ROUTERS: (state, routes) => {
      state.sidebarRouters = constantRoutes.concat(routes);
    },
     SET_INDEX_PAGE:(state,indexPage)=>{
      state.indexPage = indexPage;
    }
  },
  actions: {
    // 生成路由
    GenerateRoutes({ commit }) {
      return new Promise(resolve => {
        // 向后端请求路由数据
        getRouters().then(res => {
          const sdata = JSON.parse(JSON.stringify(res.data))
          const rdata = JSON.parse(JSON.stringify(res.data))
          //修改默认首页
          const indexdata = res.data[0].path+'/'+res.data[0].children[0].path
          const sidebarRoutes = filterAsyncRouter(sdata)
          const rewriteRoutes = filterAsyncRouter(rdata, false, true)
          const asyncRoutes = filterDynamicRoutes(dynamicRoutes);
          rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true })
          router.addRoutes(asyncRoutes);
          commit('SET_ROUTES', rewriteRoutes)
          commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes))
          commit('SET_DEFAULT_ROUTES', sidebarRoutes)
          commit('SET_TOPBAR_ROUTES', sidebarRoutes)
          //修改默认首页
          commit('SET_INDEX_PAGE',indexdata)
          resolve(rewriteRoutes)
        })
      })
    }
  }
}
  1. ruoyi-ui/src/router/index.js注释代码
  {
    path: '',
    component: Layout,
    redirect: 'index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/index'),
        name: 'Index',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },

在这里插入图片描述

  1. ruoyi/src/utils/request.js 和 ruoyi/src/layout/components/Navbar.vue 修改一处代码
  store.dispatch('LogOut').then(() => {
            location.href = '/login';
          })

在这里插入图片描述
在这里插入图片描述

5.ruoyi-ui/src/views/login.vue修改代码

// this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
   this.$store.dispatch('GetInfo').then(res => {
     const roles = res.roles
     this.$store.dispatch('GenerateRoutes', { roles }).then(accessRoutes => {
       var heardPath=accessRoutes[0].path.split("/")[1]==''?"":accessRoutes[0].path;
       this.$router.addRoutes(accessRoutes) 
       let pathIndex = ''
       pathIndex = heardPath + '/' + accessRoutes[0].children[0].path 
       if (pathIndex != '') {
         this.$router.push({ path: pathIndex  }).catch(() => {})
       }
    })
  })
  1. ruoyi-ui/src/components/Breadcrumb/index.vue注释代码
  if (!this.isDashboard(first)) {
     matched = [{ path: '/index', meta: { title: '首页' }}].concat(matched)
  }

在这里插入图片描述

7.点击左侧菜单栏上的系统名称后跳转404页面
在这里插入图片描述
需要修改ruoyi-ui/src/router/index.js 中 component: () => import(‘@/views/error/404’),

{
    path: '/404',
    //component: () => import('@/views/error/404'),
    component: () => import('@/views/system/user/profile/index'),
    hidden: true
  },

参考:若依怎么去掉首页,登录后自动跳转第一个菜单

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值