Commit 9f5ed82cdfe812662e96d164db1e43b6a06958c8

Authored by RuoYi
1 parent b7002448

动态加载路由 页面刷新问题

ruoyi-ui/src/router/index.js
... ... @@ -27,6 +27,17 @@ import Layout from '@/layout'
27 27 // 公共路由
28 28 export const constantRoutes = [
29 29 {
  30 + path: '/redirect',
  31 + component: Layout,
  32 + hidden: true,
  33 + children: [
  34 + {
  35 + path: '/redirect/:path*',
  36 + component: () => import('@/views/redirect')
  37 + }
  38 + ]
  39 + },
  40 + {
30 41 path: '/login',
31 42 component: () => import('@/views/login'),
32 43 hidden: true
... ... @@ -93,8 +104,7 @@ export const constantRoutes = [
93 104 meta: { title: '修改生成配置' }
94 105 }
95 106 ]
96   - },
97   - { path: '*', redirect: '/404', hidden: true }
  107 + }
98 108 ]
99 109  
100 110 export default new Router({
... ...
ruoyi-ui/src/store/modules/permission.js
... ... @@ -20,6 +20,7 @@ const permission = {
20 20 // 向后端请求路由数据
21 21 getRouters().then(res => {
22 22 const accessedRoutes = filterAsyncRouter(res.data)
  23 + accessedRoutes.push({ path: '*', redirect: '/404', hidden: true })
23 24 commit('SET_ROUTES', accessedRoutes)
24 25 resolve(accessedRoutes)
25 26 })
... ...
ruoyi-ui/src/views/redirect.vue 0 → 100644
  1 +<script>
  2 +export default {
  3 + created() {
  4 + const { params, query } = this.$route
  5 + const { path } = params
  6 + this.$router.replace({ path: '/' + path, query })
  7 + },
  8 + render: function(h) {
  9 + return h() // avoid warning message
  10 + }
  11 +}
  12 +</script>
... ...