其他分享
首页 > 其他分享> > 查漏补缺——路由显示的是http://localhost:8080/#/,后面带有井号,应该怎么把它去掉?

查漏补缺——路由显示的是http://localhost:8080/#/,后面带有井号,应该怎么把它去掉?

作者:互联网

问题

如题所示

答案

vue地址去掉 #

VUE路由去掉“#”

修改前源码是这样的:

export default new Router({
  routes: [
    {
      path: '/',
      name: 'hzhHome',
      component: () => import('@/views/hzhHome.vue'),
      meta: { title: '首页' }
    },
    {
      path: '/hzhSearch/:words',
      name: 'hzhSearch',
      component: () => import('@/views/hzhHome.vue'),
      meta: { title: '搜索', params: 'words'}
    },
    {
      path: '/hzhAbout',
      name: 'hzhAbout',
      component: () => import('@/views/hzhAbout.vue'),
      meta: { title: '关于' }
    },
    {
      path: '/hzhFriend',
      name: 'hzhFriend',
      component: () => import('@/views/hzhFriend.vue'),
      meta: { title: '友链' }
    },
    {
      path: '/hzhArticle',
      name: 'hzhArticle',
      component: () => import('@/views/hzhArticles.vue'),
      meta: { title: '文章' } 
    }
  ]
})

修改之后源码是这样的:

export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'hzhHome',
      component: () => import('@/views/hzhHome.vue'),
      meta: { title: '首页' }
    },
    {
      path: '/hzhSearch/:words',
      name: 'hzhSearch',
      component: () => import('@/views/hzhHome.vue'),
      meta: { title: '搜索', params: 'words'}
    },
    {
      path: '/hzhAbout',
      name: 'hzhAbout',
      component: () => import('@/views/hzhAbout.vue'),
      meta: { title: '关于' }
    },
    {
      path: '/hzhFriend',
      name: 'hzhFriend',
      component: () => import('@/views/hzhFriend.vue'),
      meta: { title: '友链' }
    },
    {
      path: '/hzhArticle',
      name: 'hzhArticle',
      component: () => import('@/views/hzhArticles.vue'),
      meta: { title: '文章' } 
    }
  ]
})

最后的效果是这样的:

image

标签:查漏,vue,8080,title,import,views,meta,path,http
来源: https://www.cnblogs.com/Huang-zihan/p/16408346.html