作者 RuoYi

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

@@ -27,6 +27,17 @@ import Layout from '@/layout' @@ -27,6 +27,17 @@ import Layout from '@/layout'
27 // 公共路由 27 // 公共路由
28 export const constantRoutes = [ 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 path: '/login', 41 path: '/login',
31 component: () => import('@/views/login'), 42 component: () => import('@/views/login'),
32 hidden: true 43 hidden: true
@@ -93,8 +104,7 @@ export const constantRoutes = [ @@ -93,8 +104,7 @@ export const constantRoutes = [
93 meta: { title: '修改生成配置' } 104 meta: { title: '修改生成配置' }
94 } 105 }
95 ] 106 ]
96 - },  
97 - { path: '*', redirect: '/404', hidden: true } 107 + }
98 ] 108 ]
99 109
100 export default new Router({ 110 export default new Router({
@@ -20,6 +20,7 @@ const permission = { @@ -20,6 +20,7 @@ const permission = {
20 // 向后端请求路由数据 20 // 向后端请求路由数据
21 getRouters().then(res => { 21 getRouters().then(res => {
22 const accessedRoutes = filterAsyncRouter(res.data) 22 const accessedRoutes = filterAsyncRouter(res.data)
  23 + accessedRoutes.push({ path: '*', redirect: '/404', hidden: true })
23 commit('SET_ROUTES', accessedRoutes) 24 commit('SET_ROUTES', accessedRoutes)
24 resolve(accessedRoutes) 25 resolve(accessedRoutes)
25 }) 26 })
  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>