vue中hash模式和history的区别

admin2023-12-28 09:30:01
  • hash模式带#,#后面的地址变化不会引起页面的刷新

  • history没有#,地址变化会引起页面刷新,更符合页面地址的规范(开发环境不刷新-webpack配置)

  • 路由模式修改成history模式

const createRouter = () => new Router({
 mode: 'history', // 需要服务端支持
 scrollBehavior: () => ({ y: 0 }),
 routes: constantRoutes
})