Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
haizhilin2013 opened this issue Jun 20, 2019 · 6 comments
Open

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

haizhilin2013 opened this issue Jun 20, 2019 · 6 comments
Labels
vue vue

Comments

@haizhilin2013
Copy link
Collaborator

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

@haizhilin2013 haizhilin2013 added the vue vue label Jun 20, 2019
@xunbie
Copy link

xunbie commented Jul 19, 2019

@liuxiaoyang1
Copy link

首先最简单的方法: 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
Copy link

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

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

@apollo-from-wuhan
Copy link

首先最简单的方法: 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
Copy link

组件导航
router-link router-view

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

@yxllovewq
Copy link

组件导航: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
Labels
vue vue
Projects
None yet
Development

No branches or pull requests

7 participants