Uni App implements background management system and Android application. After successful login, the Android phone can return to the login page. After successful logout, the Android phone can return to the login page again.
Scene:
When not logged in, opened the app will show the login page, if the login is displayed the first TAB page Due to the bottom of the TAB, there can be at most three and five have been occupied, no redundant TAB to the login page, if you log in on the second page, then, under the ios left sliding on the screen, will return to a layer, Android’s physical back button will also go up, so the login page is not visually the first page
Solutions.
Create a separate login page login/index.vue Configure the login page to page.json, note: place it in the first !!!! Change the startup page to the login page. Otherwise, the login page is displayed on the home page.
PopGesture: “None “// Disable ios default gesture closing pages
Do the same in routes.js,
Use the token in the global route front-guard in the Router interceptor to determine whether a jump is allowed and to the login page by default
// Global route front-guard router.beforeEach((to, from, next) => {let token=uni.getStorageSync(ACCESS_TOKEN); if(token){ if (whiteList.indexOf(to.path) ! == -1 && whiteList.indexOf(from.path) == -1) { next(false) }else{ next() } }else{ if (whiteList.indexOf(to.path) ! == -1) { next() }else{ next({ path: '/pages/login/index'}) } }Copy the code
Physical return to the login page is not allowed when the token exists. Router You can use uni-simple-router ext.dcloud.net.cn/plugin?id=5…
Block the default operation login/index.vue on the login page
onBackPress(e) { return true; // Return true to prevent default action},Copy the code
To exit the event, jump to use uni.relaunch()!!
HandleClick_checkout () {const app = this uni.showModal({title: 'sweet tip ', content:' Are you sure to exit? CancelText: "cancel ", confirmText:" confirm ", success: function success(res) { if (res.confirm) { store.dispatch('Logout') .then(result => { console.log(result) app.$toast( SetTimeout (() => uni.reLaunch({url:'/pages/login/index'})}, 1000) }) .catch(err => { app.$toast(err) }) } } });Copy the code
This solves the problem of the physical return of the UNI App login page.