路由之间是怎么跳转的?有哪些方式?
-
首先最简单的方法: 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)
} -
1.在vue中引入vue-router模块
2.定义路由跳转规则有以下方式:
1.在页面使用来定义导航链接
2.使用编程式导航,push,replace,go -
首先最简单的方法: 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)
}写反了吧?
-
组件导航
router-link router-view编程导航
router.push
router.replace
router.go -