Use location.replace when redirecting to avoid history navigation issues