uniapp 小程序 监听全局路由跳转 获取路由参数
- app.vue中 api文档
javascript
onLaunch: function(options) {
let that = this;
let event = ['navigateTo', 'redirectTo', 'switchTab', 'navigateBack'];
event.forEach(item => {
uni.addInterceptor(item, { //监听跳转
//监听跳转
success(e) {
that.watchRouterSuccess()
},
})
})
},
methods: {
watchRouterSuccess() {
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
let path = currentPage.$page.fullPath
console.log(path,"这个是完整的跳转路径,可获取参数")
},
}
- 搞定!亲测有效