Creating a battery backup unit
To answer this a bit clearer, when the charging circuit (aka rectifying the mains, power to recharge) goes out.  It counts as a "closed circuit".  Yes you can add measures and all, problem is, it may drain your resources. Deep cycle batteries can help cause they slowly trickle power, enough to run your router.  I am running a little bit of sleep.  So no need of special circuitry to switcj from charge to drain.  However if that becomes an issue, just have an off on switch on the discharge ONLY.  Otherwise it can charge your battery and power your router if assuming the circuit is parallel.  Hopefully it makes sense!