Skip to content

[vue] 路由之间是怎么跳转的?有哪些方式? #371

Open
@haizhilin2013

Description

@haizhilin2013
Collaborator

[vue] 路由之间是怎么跳转的?有哪些方式?

Activity

liuxiaoyang1

liuxiaoyang1 commented on Nov 19, 2019

@liuxiaoyang1

首先最简单的方法: to里面可以写对象
方法二:编程式当行: this.$router.go/replace/push
注意这里有一个小bug,vue2.0-中没有捕获这个异常,就是多次点击请求同一个路由会报错误,你可以手动捕获异常 在mins.js中加入以下代码
// 多次请求同一个路由手动捕获异常

const originalPush = Router.prototype.replace
Router.prototype.replace = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
const originalReplace = Router.prototype.push
Router.prototype.push = function push(location) {
return originalReplace.call(this, location).catch(err => err)
}

WenJieLi1998

WenJieLi1998 commented on Apr 19, 2020

@WenJieLi1998

1.在vue中引入vue-router模块
2.定义路由跳转规则

有以下方式:
1.在页面使用来定义导航链接
2.使用编程式导航,push,replace,go

apollo-from-wuhan

apollo-from-wuhan commented on Jun 6, 2020

@apollo-from-wuhan

首先最简单的方法: to里面可以写对象
方法二:编程式当行: this.$router.go/replace/push
注意这里有一个小bug,vue2.0-中没有捕获这个异常,就是多次点击请求同一个路由会报错误,你可以手动捕获异常 在mins.js中加入以下代码
// 多次请求同一个路由手动捕获异常

const originalPush = Router.prototype.replace
Router.prototype.replace = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
const originalReplace = Router.prototype.push
Router.prototype.push = function push(location) {
return originalReplace.call(this, location).catch(err => err)
}

写反了吧?

zhaofeipeter

zhaofeipeter commented on Aug 3, 2020

@zhaofeipeter

组件导航
router-link router-view

编程导航
router.push
router.replace
router.go

yxllovewq

yxllovewq commented on Mar 10, 2022

@yxllovewq

组件导航:router-link的to属性
编程导航:router的push、replace、go方法
导航地址参数可以为:
字符串:‘/index/1?id=1’
对象:{ path: '/index/1', query: { id:1 } } 或 { name: 'index', params: { num: 1 }, query: { id: 1 } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @haizhilin2013@zhaofeipeter@WenJieLi1998@liuxiaoyang1@xunbie

        Issue actions

          [vue] 路由之间是怎么跳转的?有哪些方式? · Issue #371 · haizlin/fe-interview