美文网首页
vue添加路由后url中http://localhost:808

vue添加路由后url中http://localhost:808

作者: JennyWeb | 来源:发表于2023-03-20 17:04 被阅读0次

情景: vue-cli脚手架 vue-router配置路径 ,npm run dev后 点击路由 发现url中有#, 从而不能成功跳转至具体页面

vue中localhost:8080地址栏的显示有两种模式:

  • 第一种是hash(默认),即mode:'hash',该模式地址栏会默认有#号。
  • 第二种是history,即mode:'history',该模式直接用url。
    在rouer下面的index.js中书写:
export default new Router({
  mode: 'history', // 即可去掉#
  routes: [
    {
      path: '/',
      name: 'home',
      component: home
    },
    {
      path: '/classify',
      name: 'classify',
      component: classify
    }
  ]
})

相关文章

网友评论

      本文标题:vue添加路由后url中http://localhost:808

      本文链接:https://www.haomeiwen.com/subject/jotprdtx.html