A good UPS is your best bet but sometimes even that won’t do the job. Three years ago, we had a bad ‘Nor’easter hit our town in Maine and we lost power for over 24 hours. My UPS kept everything up for about 8 hours but that was it.
I had a friend go over and try to reboot the router but it just wouldn’t sync back up. We tried for about two hours and tried everything we could think of. No Joy. We finally gave up and he left, but he left with everything powered on. Two months later, we had another power outage and that did the trick. Don’t ask me what changed in the ensuing 2 months but something did.