1.在頁(yè)面元素加載之前聲明全局event方法,切記一定要在監(jiān)聽(tīng)事件之前聲明
var event = new Event("setItemEvent");
2.注冊(cè)監(jiān)聽(tīng)此event,并且處理相應(yīng)的跳轉(zhuǎn),并且在跳轉(zhuǎn)之后把該數(shù)據(jù)刪除掉
window.addEventListener("setItemEvent", function (event) {
var urlType = localStorage.getItem("urlTypefromLocal");
if (!urlType || urlType.length == 0){
return;
}
if (urlType.indexOf("temp://") == 0) {
localStorage.removeItem("urlTypefromLocal");
navCtrl.push(LoginPage);
}
});
3.index.html中注入簡(jiǎn)單的js方法,用于傳相應(yīng)的跳轉(zhuǎn)scheme參數(shù)過(guò)來(lái),并將此跳轉(zhuǎn)的scheme參數(shù)保存到本地緩存用于處理跳轉(zhuǎn),接到參數(shù)的同時(shí)分發(fā)全局事件event
function temp(e){
localStorage.setItem("urlTypefromLocal",e);
window.dispatchEvent(event);
}
3步完美解決ionic3 應(yīng)用之間的跳轉(zhuǎn),歐耶!