Fix redirect back to referrer logic (cannot use router)