jiuyiUniapp/shop/utils/router.js

48 lines
876 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 路由对象
* 中心思想:需要路由鉴权,由于uni-app没有vue中的全局钩子函数所以封装了Router对象。
* 说明应用中的路由跳转尽量使用该Router的方法并配合config中的路由表对象进行跳转。
*
* 示例this.$mRouter.push({route:this.$mRoutesConfig.main,query:{a:1}})
*
*/
class Router {
constructor() {
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) {
// #ifdef H5
history.back();
// #endif
// #ifndef H5
uni.navigateBack({
delta
});
// #endif
}
}
export default new Router();