如何使用JavaScript进行重定向?

So as you can see, I'm using a loginform that validates user and password online, generates a token and is supossed to once the token exists redirect the page to pacientes.html. the problem starts in renderApp. It does execute the window.location.href but to redirect Ihave to manually refresh the page. am I doing something wrong? pls help

let ruta = 'login'

const renderApp = () =>{
    const token = localStorage.getItem('token')
    if (token) {
        window.location.href = "pacientes.html"

    }
}

window.onload= () => {
    renderApp()
    const loginForm= document.getElementById('login')
    loginForm.onsubmit = (e) =>{
        e.preventDefault()
        e.stopPropagation()
        const cedula = document.getElementById('cedula').value
        const password = document.getElementById('password').value

        fetch('https://janfa.gharsnull.now.sh/api/auth/login', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({cedula, password})
        }).then( x => x.json())
          .then( respuesta => {
            localStorage.setItem('token' , respuesta.token)
            ruta = 'users'
          })
    }

}