Android returns to the previous page
Environment : uni-app develops an H5 project, and the H5 project link webview is embedded in the app.
Situation : Android jumps from the page link to enter the map webpage for navigation and then returns to the original page. The original page triggers reloading and refreshes the state; it is hoped that the state can be retained and the reason is not refreshed
. : Android will not get the page from the cache, but IOS will get the page from the cache.
Solution : Android cannot be controlled to refresh the page, and the page can only be restored by storing page information.
1. Store information when jumping to navigation
openLocation(e) {
const {
latitude, longitude, address } = e.currentTarget.dataset;
if (latitude && longitude) {
// #ifdef H5
uni.setStorageSync('activeTab', this.activeTab)
let url = `https://apis.map.qq.com/tools/routeplan/eword=${
address}&epointx=${
latitude}&epointy=${
longitude}?referer=${
应用名称}&key=${
腾讯地图的key}`
window.location.href = url
// #endif
// #ifdef MP-WEIXIN
uni.openLocation({
latitude: Number(latitude),
longitude: Number(longitude),
name: address || ''
});
// #endif
}
},
2. Restore the page when reloading
// 从地图导航中返回上级页面与重新进入该应用的情况是高度相似的,该应用进入过地图导航的情况下路由历史history的长度会增加,通过该值进行判断是否需要还原页面
created() {
console.log('new store created');
// #ifdef H5
let tab = uni.getStorageSync('activeTab')
if(history.length == 2 && tab !== undefined) {
this.setData({
activeTab: tab
});
uni.setStorageSync('activeTab', undefined)
}
// #endif
}