[Vue]防止路由重复跳转

[Vue]防止路由重复跳转

js 复制代码
// 获取当前路由的原始路径(包括重定向的处理)
const currentPath = this.$route.redirectedFrom || this.$route.path;

// 判断目标路径是否与当前路径相同
if (currentPath !== item.url) {
  this.$router.push({ path: item.url });
} else {
  console.log('目标页面与当前页面相同,不进行跳转');
}
  • this.$route.redirectedFrom

重定向的来源

  • this.$route.path

this.$route.path:这是当前路由的路径(不包括查询参数和哈希)。它表示的是当前页面的实际路径,比如 /strategy/security-policy。当路由发生重定向时,this.$route.path 会反映最终的目标路径(即重定向后的路径)

  • this.$route.fullPath

这是当前路由的完整路径,包含路径、查询参数和哈希。例如,/strategy/security-policy?id=123#section1。如果路由发生了重定向,fullPath 也会是重定向后的路径。

相关推荐
Aric_Jones2 小时前
JavaScript 从入门到精通:完整语法指南
开发语言·javascript·ecmascript
岱宗夫up2 小时前
FastAPI入门(上篇):快速构建高性能Python Web API
开发语言·前端·python·fastapi
紫陌涵光3 小时前
112. 路径总和
java·前端·算法
漠月瑾-西安3 小时前
CVE-2025-55182漏洞解析:你的React项目安全吗?
前端·安全·react.js
No丶slovenly3 小时前
flutter笔记-输入框
前端·笔记·flutter
国产化创客3 小时前
ESP32+Web实现智能气象站
前端·物联网·智能家居·智能硬件
coderYYY4 小时前
VSCode终端启动报错
前端·ide·vscode·npm·编辑器
西门吹-禅5 小时前
文本搜索node js--meilisearch
开发语言·javascript·ecmascript
tod1135 小时前
Redis 数据类型与 C++ 客户端实践指南(redis-plus-plus)
前端·c++·redis·bootstrap·html
Sylvia33.5 小时前
火星数据:棒球数据API
java·前端·人工智能