我有以下代码
var windowHref = window.location.href;
if (windowHref.includes('/project/')) {
var splitURL = windowHref.split('/');
window.location.href = windowHref.substring(0, windowHref.indexOf('#/project')) + '?projectId=' + splitURL[splitURL.length - 2];
}
window.location.reload(true);
在执行上述代码之前,window.location.href
的值为
https://localhost:44301/default.aspx#/project/16a76abd-5b5b-4c63-822f-2bfd7f133adc/home
并且在执行之后,我希望它的值类似于
https://localhost:44301/default.aspx?projectId=16a76abd-5b5b-4c63-822f-2bfd7f133adc
但是当行
window.location.href = windowHref.substring(0,windowHref.indexOf('#/project')) + '?projectId=' + splitURL[splitURL.length - 2];
,window.location.href
保持不变。
的结果
windowHref.substring(0,windowHref.indexOf('#/project')) + '?projectId=' + splitURL[splitURL.length - 2];
是
https://localhost:44301/default.aspx?projectId=16a76abd-5b5b-4c63-822f-2bfd7f133adc
我做错了什么?
答案 0 :(得分:0)
我建议删除行var href = window.location.href;
var index = href.indexOf('#/project/');
if(index!==-1){
var splitURL = href.substring(index,href.length).replace('#/project/','?projectId=').split('/');
window.location.href = splitURL[0];
}
,因为在使用window.location.href
JSONObject json = new JSONObject();
json.put("requestType", "xxxx");
json.put("projectToken", "xxxxxxxxxxxxxx");
StringEntity params = new StringEntity(json.toString());
post.setEntity(params);