Vue的路由实现模式:hash模式和history模式

1、hash模式:在浏览器中符号"#", #以及#后面的字符称之为hash, 用window.location.hash读取。 特点:hash虽然在URL中, 但不被包括在HTTP请求中;用来 指导浏览器动作,对服务端安全无用, hash不会重加载页面

javascript 复制代码
import {  createWebHashHistory } from 'vue-router'

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

2、history模式:history采用HTML5的新特性, 且提供了两个新方法:

2.1) pushState()

2.2) replaceState()可以对浏览器历史记录栈进行修改,以及popState事件的监听到状态变更

javascript 复制代码
import {  createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(),
  routes
})
相关推荐
好_快39 分钟前
Lodash源码阅读-baseMatchesProperty
前端·javascript·源码阅读
好_快41 分钟前
Lodash源码阅读-hasPath
前端·javascript·源码阅读
好_快43 分钟前
Lodash源码阅读-hasIn
前端·javascript·源码阅读
好_快1 小时前
Lodash源码阅读-basePropertyDeep
前端·javascript·源码阅读
vvilkim4 小时前
深入理解 TypeScript 中的 implements 和 extends:区别与应用场景
前端·javascript·typescript
武昌库里写JAVA5 小时前
SpringCloud
vue.js·spring boot·毕业设计·layui·课程设计
刺客-Andy7 小时前
前端加密方式 AES对称加密 RSA非对称加密 以及 MD5哈希算法详解
前端·javascript·算法·哈希算法
记得早睡~8 小时前
leetcode122-买卖股票的最佳时机II
javascript·数据结构·算法·leetcode
ElasticPDF-新国产PDF编辑器8 小时前
Vue 项目 PDF 批注插件库在线版 API 示例教程
前端·vue.js·pdf
拉不动的猪8 小时前
react基础2
前端·javascript·面试