Javascript window.location.assign(varString)不起作用

Javascript window.location.assign(varString)不起作用,javascript,url,hyperlink,forward,assign,Javascript,Url,Hyperlink,Forward,Assign,我有java脚本函数来检查URL并拆分它, 我问了一个问题,取决于答案,它将转发到用户页面 在我使用window.location.assign()之前,一切正常; 在(=window.location.assign(path);)中使用字符串,而不是固定URL(=window.location.assign(“”;) 我能做什么? 谢谢 var register=...; var login=...; function link(type) { var urlPath = document.U

我有java脚本函数来检查URL并拆分它, 我问了一个问题,取决于答案,它将转发到用户页面 在我使用window.location.assign()之前,一切正常; 在(=window.location.assign(path);)中使用字符串,而不是固定URL(=window.location.assign(“”;) 我能做什么? 谢谢

var register=...;
var login=...;
function link(type) {
var urlPath = document.URL.split("/");
if (type == "register") {
    var path= urlPath[2] + register;
    window.location.assign(path);
}
else {
    var path = urlPath[2] + login;
    window.location.assign(path);

}
event.preventDefault();

}您应该使用完整的URL

window.location.assign(urlPath[0]+'/'+urlPath[1]+'/'+urlPath[2]+register);

window.location.assign(urlPath[0]+'/'+urlPath[1]+'/'+urlPath[2]+path);


您应该使用完整的URL

window.location.assign(urlPath[0]+'/'+urlPath[1]+'/'+urlPath[2]+register);

window.location.assign(urlPath[0]+'/'+urlPath[1]+'/'+urlPath[2]+path);


你知道原因是什么吗?@user1913615,我想可能会有不同的做法,但是你传递给
assign
的任何内容都会成为地址栏中的URL。你知道原因是什么吗?@user1913615,我想可能会有不同的做法,但是你传递给
assign
的任何内容都会成为地址栏中的URL。这应该是整件事。