jiuyiUniapp/shop/common/router.js

43 lines
805 B
JavaScript
Raw Permalink Normal View History

2024-12-18 15:46:27 +08:00
/*
* 路由对象
* 中心思想需要路由鉴权,由于uni-app没有vue中的全局钩子函数所以封装了Router对象
* 说明应用中的路由跳转尽量使用该Router的方法并配合config中的路由表对象进行跳转
*
* 示例this.$mRouter.push({route:this.$mRoutesConfig.main,query:{a:1}})
*
*/
class Router {
constructor(arg) {
this.callBack = () => {
};
}
beforeEach(callBack) {
if (callBack instanceof Function) this.callBack = callBack;
}
push(to) {
this.callBack('navigateTo', to);
}
redirectTo(to) {
this.callBack('redirectTo', to);
}
reLaunch(to) {
this.callBack('reLaunch', to);
}
switchTab(to) {
this.callBack('switchTab', to);
}
back(delta) {
uni.navigateBack({
delta
})
}
}
export default new Router();