It could be disconnecting for a number of reasons, but before getting into that, when you're on wifi, turn off mobile data.
If you get close to a microwave oven that's running, and you're on 2.4GHz wifi, the oven will interfere with the wifi. (Wifi maximum radiated power is 4 Watts, a microwave oven can be 1,200 Watts, and the power falls off as the square of the distance, so if you're 10 times as far from the router as you are from the oven, even if they were running the same power level, the microwave signal would be 100 times as much as the wifi signal.)
If you're on 5GHz wifi, and the house is large, so the signal is going through a few walls (even sheetrock), it can weaken the signal enough that you disconnect.
You may have a neighbor using the same wifi channel that you are. If you get to a position that the neighbor's signal is stronger than yours, you lose yours (and disconnect).
If you're directly under or over the router, routers fire horizontally, so - especially if you're using 5GHz - the signal is going to be weak enough to disconnect you as you pass the dead spot. Especially if the router is in the basement and you're on the second floor (or the reverse).
The antenna cable (inside the phone) could be loose.
The wifi transceiver could be intermittent.
Troubleshooting wifi problems is an entire field, and it's a difficult one to do when someone is there with test equipment. Doing it online, with no information other than "my phone disconnects" is - at best - a guessing game.