Hello,
In my app, I listen to offline and online events using the cordova network plugin… I fire a toast on offline and redirect using app.navigate('/to-no-network-page/'). I want that once network comes back, I immediately redirect user to their previous page in history… I have found router.back(); but it’s not working as I dont know how to use it…
`//LISTEN FOR ONLINE EVENT
$$(document).on(‘online’, function () {
var toastTop = app.toast.create({
text: ‘Awesome, We Are BACK ONLINE!’ ,
position: ‘top’,
closeTimeout: 3000
});
//LISTEN TO OFFLINE EVENT
$$(document).on(‘offline’, function () {
var toastTop = app.toast.create({
text: 'Ooops, Seems We Lost A Reliable INTERNET CONNECTION, Let’s Try Re-connecting… ',
position: ‘top’,
closeTimeout: 3000
});
toastTop.open();
app.router.navigate(’/no-network/’); //To NO NETWORK PAGE
});`
i have also tried… app.router.back(), view.router.back() but I keep getting his error in the console…app.js:59 Uncaught ReferenceError: view is not defined at HTMLDocument.<anonymous> (app.js:59) at HTMLDocument.l (framework7.min.js:12) at Object.fireDocumentEvent (cordova.js:233) at network.js:73 at Object.callbackFromNative (cordova.js:291) at Object.callbackSuccess (cordova.js:271) at onSuccess (cordova.js:969) at network.js:43
Error message is self explaining, you don’t have view variable in the place you write this code. You can use app.views.main instead to reference main view
Thanks @nolimits4web,
Below I detech the event online… $$(document).on('online', function () { var toastTop = app.toast.create({ text: 'Awesome, We Are ONLINE!' , position: 'top', closeTimeout: 4000 }); toastTop.open(); //WANNA REDIRECT THE USER BACK TO THE PAGE THEY ON HERE**** });
Here is how I redirect them on offline…
$$(document).on('offline', function () { var toastTop = app.toast.create({ text: 'Ooops, Seems We Lost A Reliable INTERNET CONNECTION, Let\'s Try Re-connecting... ', position: 'top', closeTimeout: 5000 }); toastTop.open(); app.router.navigate('/no-network/'); //To NO NETWORK PAGE });
I want to simply take them beack to where they were before…
Here Is my no-network-page… (On offline, It detects very well and actually navigates to that page…)
I keep getting errors in my console… In the rest of the app, I use async routing as I have to connect to my MySQL DB online… So I keep making requests and resolving or rejecting…