samuel toh samuel toh - 9 months ago 25
Javascript Question

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

Answer Source

Your code that declares restVar:

var restVar = arrVars.join("/");

Returns an array, which wouldn't have 'reload()' available as a function. After you get your new URL, you might try window.location (https://www.w3schools.com/js/js_window_location.asp)