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
})
相关推荐
嘟嘟071733 分钟前
顺时针螺旋填充 n×n 矩阵:手撕 generateMatrix 的四个 for 循环
javascript·算法·面试
weixin_BYSJ198742 分钟前
springboot技能与工具共享小程序---附源码29657
java·javascript·spring boot·python·小程序·django·php
张元清1 小时前
React useSessionStorage Hook:刷新不丢、只属于当前标签页的状态 (2026)
前端·javascript·react.js
weixin_BYSJ19871 小时前
flask民族服饰饰品商城小程序---附源码37399
java·javascript·spring boot·python·小程序·django·php
xiaominlaopodaren1 小时前
three.js最小地图运行时(一):视图状态
javascript·gis·three.js
Orange_sparkle1 小时前
从五个 TypeScript 文件看懂 Coding Agent:一次 nano-pi 学习复盘
javascript·学习·typescript
摸鱼研究员1 小时前
neverthrow,ts 中优雅的异常处理方案
前端·javascript
烬羽1 小时前
求第 K 大,为什么反而要用最小堆?
javascript·数据结构·算法
jingchao19982 小时前
Cannot read properties of null (reading ‘insertBefore‘)
前端·javascript·vue.js
梦醒沉醉2 小时前
2、JavaScript控制流和错误处理
javascript