Should I use window.location.replace('/') or window.location.href=window.location.origin in the process of logging out?

Viewed 213

In a logout button, should I be using window.location.replace('/') or window.location.href=window.location.origin. What is the difference between these two methods? I know that both of them clear the current href from the history, so the url won't be accessible to the user after logging out using either of them.

1 Answers

if you are using next.js you can use next/router which is a better approach to it.

import { useRouter } from 'next/router'
const router = useRouter()
//and then you can do it like this 
router.replace('/')
//or
router.push('/')
Related