我在重定向获取现有网址时遇到问题。我有一个页面,上面有谷歌图表,我在条形图中的条形图中添加了一个侦听器。当用户单击其中一个条形图时,case 语句会确定要传递给路由器的 id。
google.visualization.events.addListener(wrapper, 'select', selectHandler);
function selectHandler() {
var selection = wrapper.getChart().getSelection()
var monthsTransform = 0;
switch(selection[0].column)
{
case 1:
monthsTransform = 0;
break;
case 2:
monthsTransform = 3;
break;
case 3:
monthsTransform = 6;
break;
case 4:
monthsTransform = 12;
break;
case 5:
monthsTransform = 18;
break;
//no need to default as already set to 0!
}
var url = "newController/newPage/" + monthsTransform;
window.location.href = url;
}
我遇到的问题是
window.location.href
将 newController/newPage 附加到现有的 url,所以它最终像:
localhost:1234/oldController/oldPage/newController/newPage/id