黄子涵

查漏补缺——路由显示的是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

posted @   黄子涵  阅读(264)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示