feat:app嵌套h5返回键
This commit is contained in:
21
src/main.ts
21
src/main.ts
@@ -23,19 +23,26 @@ declare global {
|
||||
appBridge?: any;
|
||||
}
|
||||
}
|
||||
// 隐藏/显示 header
|
||||
appBridge.setHeaderShown(true);
|
||||
// 设置系统状态栏明暗主题
|
||||
appBridge.setStatusBarStyle('light');
|
||||
// 定义路由是否可以返回的判断
|
||||
const routerCanGoBack = () => {
|
||||
const position = router.options.history.state?.position;
|
||||
return typeof position === 'number' && position > 0;
|
||||
};
|
||||
router.beforeEach((to, from, next) => {
|
||||
if (to.query.digitalYiliToken) {
|
||||
utils.setSessionStorage('xToken', to.query.digitalYiliToken);
|
||||
}
|
||||
// 设置 header 标题
|
||||
appBridge.setTitle(to.meta.title as string);
|
||||
// 添加 Android 返回按钮监听方法
|
||||
window.onAndroidBack = () => {
|
||||
if (routerCanGoBack()) {
|
||||
router.go(-1);
|
||||
} else {
|
||||
appBridge.navigateBack();
|
||||
}
|
||||
};
|
||||
next();
|
||||
});
|
||||
|
||||
app.use(createPinia());
|
||||
app.use(router);
|
||||
app.mount('#app');
|
||||
app.mount('#app');
|
||||
Reference in New Issue
Block a user