例如我有以下网址:
http://server:port/?parameter#token;ID=com.test;args=one&two&three
如果我想从 URL 中删除 ID 和参数而不重新加载页面,那么该怎么做。
注意:现在我正在使用下面的代码执行此操作,并且我正在寻找更好的选择
PlaceRequest currentPlaceRequest = placeManager.getCurrentPlaceRequest();
final String counts= currentPlaceRequest.getParameter( "args", null );
String id = currentPlaceRequest.getParameter( "ID", null );
String url = Window.Location.getHref();
if( counts!= null && !counts.isEmpty() )
{
if( id!= null && !id.isEmpty() )
{
String counts= ";" + "args" + "=" + counts;
String urlToReplace = url.replace( counts, "" );
Window.Location.replace( urlToReplace );
}
最佳答案
您可以使用 History.getToken
检索当前 token ,对其进行处理,然后使用 History.newItem
设置它。请注意,根据您的设置(使用 Activities and Places 或 mvp4g/gwtp 等),这可能会触发应用程序中的另一个 Activity 。
关于java - 如何从 GWT 应用程序中的 URL 中删除哈希参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27016836/