function checkToken(){ instance.get("token", { withCredentials: true}) .then(function(response) { if(location.pathname == "/") { location.href="/html/home.html"; } }) .catch(function(error){ if(location.pathname != "/"){ location.href="/"; } }); }