如何在历史js插件中添加问号参数而不是正斜杠

How to add question mark parameter instead of forward slash in history js plugin

本文关键字:参数 历史 js 插件 添加      更新时间:2023-09-26


我正试图这样更改网址(http://www.rangde.org/gift-cards?theme=Anniversary)
但我得到的输出是(http://www.rangde.org/gift-cards/?theme=Anniversary)
我不希望问号参数前面有正斜杠,请帮我解决这个问题
我的脚本在这里:

 History.pushState({state:1,rand:Math.random()}, 'Designs', '?theme=Diwali');   
    function(){     
                var History = window.History, // Note: We are using a capital H instead of a lower h
                State = History.getState(),
                $log = $('#log');
                History.log('initial:', State.data, State.title, State.url);
                History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
                var State = History.getState(); // Note: We are using History.getState() instead of event.state
                History.log('statechange:', State.data, State.title, State.url);
                }); 
            }

不确定这是一个bug还是一个功能,但看起来向查询中添加一个实际的URL有帮助:

History.pushState({}, 'New title', window.location.pathname + "?" + ...);   

这是无法通过Histor.js或任何其他客户端脚本实现的。。。这应该在服务器端完成。