@ph_black nuclearcat idea about the capacitor is a good idea
a capacitor is a device that charge electric energy , this electric energy will be given to the router for a short period of time until the ups/supply is reapplied.
just go to any electronics store and ask for a 4700 microfarad 50Volt capacitor
it has a cylindrical shape with two bare wires emerging from one side ,
one of them is marked with a line or a negative sign on the body of the cylinder it should be connected to the negative wire of the dc cable connected to your router
the other wire emerging from the cylinder is the positive wire it should be connected(soldered) to the positive wire of the dc cable connected to your router,
if this doesn't solve the problem you should use a diode before the capacitor from the side of the adapter.