uniapp listens for routing jumps

Need to implement an event that can be triggered every time the listening page jumps, use uni.addInterceptor uni interceptor to implement, intercept the routing jump method

// APP.vue文件
<script>
export default {
	onLaunch: function () {
		let that = this,
			naviArr = [
				'navigateTo',
				'redirectTo',
				'reLaunch',
				'switchTab',
				'navigateBack',
			]
		for (let i of naviArr) {
			uni.addInterceptor(i, {
				//监听跳转
				success(e) {
					that.watchRouter()
				},
			})
		}
		that.watchRouter()
		//console.log('App Launch')
	},
	onShow: function () {
		//console.log('App Show')
	},
	onHide: function () {
		//console.log('App Hide')
	},
	methods: {
		watchRouter() {
			console.log('监听uniapp页面路由跳转')
		},
	},
}
</script>

<style lang="scss">
/*每个页面公共css */
</style>

Monitor the physical return key on the mobile terminal

Note: WeChat applets are not supported.

methods: {
},
onBackPress(options) {
  console.log("用户按下物理返回键");
},

Guess you like

Origin blog.csdn.net/weixin_43743175/article/details/127313441