Hello,
I’m looking for a way to check all pages, without rewriting the same code on each page, if there is an internet connection.
With @ capacitor / network I was able to get if there is a connection or not, but now I have to do two things:
1-Implement the code in all pages (I tried with the providers / services but I couldn’t)
2-When there is no connection I have to refer to a specific page ‘NotConnected.html’ but when there is no connection it does not load the page
You to add a listener when the network change. You can try the following:
Note: The Network is from @capacitor/network
Network.addListener('networkStatusChange', status => {
console.log('Network status changed', status);
// Redirect to NotConnected.html if not connected
});
This is my app.components.ts file
import { Component } from ‘@angular/core’;
import { Platform, NavController } from ‘@ionic/angular’;
import { PluginListenerHandle } from ‘@capacitor/core’;
import { Network } from ‘@capacitor/network’;
This way it seems to work, I see in the url changing from ‘home’ to ‘network’ the problem is that I don’t see anything on the screen. Doesn’t load the page. It appears that without connection it is unable to load the page.