关于#vue.js#的问题:1.为什么需要单独为重定向创建一个路由; 2.往后需要怎么利用到这个路由?

1.为什么需要单独为重定向创建一个路由?

rouer/index.js

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  }
]

@/views/redirect/index

<script>
export default {
  created() {
    const { params, query } = this.$route
    const { path } = params
    this.$router.replace({ path: '/' + path, query })
  },
  render: function(h) {
    return h() // avoid warning message
  }
}
</script>

2.这样创建的好处是什么?后面需要怎么利用到?

项目引用自 https://github.com/PanJiaChen/vue-element-admin