How to check availability of the router in esp 32 without connecting to it?

Hello, I want to check the availability of my router to connect my esp 32, before connecting it.
I want to do this in the Void loop. if in case my router got disconnected. I want to repair it without disturbing the code as I have both manual and internet overwrite....... I am new Hear pls help me, thank u in advance

You can use the WiFi.scanNetworks() function to find all the networks nearby. You just need to get through the list and check whether your network is in the list.

There is a Example in the ESP32 library.

File -> Examples -> WiFi -> WiFiScan