JavaScript — How to redirect to another page

All About Code
1 min readOct 3, 2022
Photo by Frida Bredesen on Unsplash

There are many ways to redirect to another page. But which is the best?

// 1. window.location
window.location.replace('http://www.example.com')
window.location.assign('http://www.example.com')
window.location.href = 'http://www.example.com'
document.location.href = '/path'
// 2. window.history
window.history.back()

--

--