How to solve "Uncaught TypeError: restVar.reload is not a function"?

My url is like this : http://myshop.dev/member/message/inbox/detail/58c508e9607a1d16f0006b3f

My function javascript is like this :

reloadMessage() {
    setTimeout(function () {
        var vars = location.href;
        var arrVars = vars.split("/");
        var lastVar = arrVars.pop();
        var lastVar = arrVars.pop();
        var restVar = arrVars.join("/");
        restVar.reload(true);
    }, 1500);
}

I want when call reloadMessage function, it will reload page to url :

http://myshop.dev/member/message/inbox

But it does not work

There exist error like this :

Uncaught TypeError: restVar.reload is not a function

How can I solve it?

Update :

If I do : console.log(restVar), the result :

http://myshop.dev/member/message/inbox

When call reloadMessage function, I want it will reload page / url : http://myshop.dev/member/message/inbox

Answers 1

  • Don't use reload for this. Just change location:

    function reloadMessage() {
        setTimeout(function () {
            var vars = location.href;
            var arrVars = vars.split("/");
            arrVars.pop();
            arrVars.pop();
            location = arrVars.join("/");
        }, 1500);
    }
    

Related Articles