Blog
首页
文档
收藏
关于
  • 在线转换时间戳 (opens new window)
  • 在线压缩图片 (opens new window)
  • Float-Double转二进制 (opens new window)
  • 文件转Hex字符串 (opens new window)

HiuZing

🍑
首页
文档
收藏
关于
  • 在线转换时间戳 (opens new window)
  • 在线压缩图片 (opens new window)
  • Float-Double转二进制 (opens new window)
  • 文件转Hex字符串 (opens new window)
  • 前端面试题

  • JavaScript

  • Vue2

  • port

  • CSS

  • Node.js

  • JavaScript优化

  • uniapp

  • Mini Program

  • TypeScript

  • 面向对象编程

  • UI组件

  • Plugin

  • Vue3

    • 教程

    • Vue Router

      • API

      • 基础

        • 入门
        • 路由模式
        • 命名路由
        • 历史记录
          • replace
            • 使用方法
            • router-link
          • 横跨历史
        • 路由传参
        • 嵌套路由
        • 命名视图
        • 重定向和别名
      • 进阶

      • 实例

    • API

    • Vuex

    • 实例处理方案

    • 文档

    • 用法

  • 性能优化

  • Axios

  • 状态管理

  • React

  • Mock

  • Icon

  • Template

  • 构建工具

  • 项目规范配置

  • Taro

  • SVG

  • React Native

  • 前端
  • Vue3
  • Vue Router
  • 基础
HiuZing
2023-03-27
目录

历史记录

​ 不同的历史模式 | Vue Router (vuejs.org) (opens new window)

# replace

采用replace进行页面的跳转会同样也会创建渲染新的Vue组件,但是在history中其不会重复保存记录,而是替换原有的vue组件;

# 使用方法

# router-link

<router-link replace to="/">Login</router-link>
<router-link replace style="margin-left:10px" to="/reg">Reg</router-link>
1
2

# 编程式导航

<button @click="toPage('/')">Login</button>
<button @click="toPage('/reg')">Reg</button>

import { useRouter } from 'vue-router'
const router = useRouter()

const toPage = (url: string) => {
  router.replace(url)
}
1
2
3
4
5
6
7
8
9

# 横跨历史

该方法采用一个整数作为参数,表示在历史堆栈中前进或后退多少步

<button @click="next">前进</button>
<button @click="prev">后退</button>

const next = () => {
	// 前进 数量不限于1
	router.go(1)
}

const prev = () => {
	// 后退
	router.back()
}
1
2
3
4
5
6
7
8
9
10
11
12
上次更新: 2024/08/14, 04:14:33
命名路由
路由传参

← 命名路由 路由传参→

最近更新
01
React Native 使用SVG
08-13
02
Docker基础命令
08-04
03
算数逻辑单元
07-30
更多文章>
Theme by Vdoing | Copyright © 2021-2024 WeiXiaojing | 友情链接
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式