总重量。删除锚点部分 url
您好,我正在使用 GWT 及其标准方式通过“History”类支持历史记录。这很方便,但是如何从网址中删除锚点部分?例如:
我的基本网址:
http://www.mysuperwebsite.com/myapp
在使用应用程序时,我移动到添加新历史记录项目的位置。
在代码中:
History.newItem("funnygame");
结果:
http://www.mysuperwebsite.com/myapp#funnygame
我再换一次地方:
在代码中:
History.newItem("notsofunnygames");
结果:
http://www.mysuperwebsite.com/myapp#notsofunnygames
然后我想回到我的主页(http://www.mysuperwebsite.com/myapp)。
代码中应该放置什么?:
????
回到:
http://www.mysuperwebsite.com/myapp
有什么标准方法可以实现我的目标吗?
如果我添加这样的内容:
History.newItem("");
或者
History.newItem(null);
网址将变成
http://www.mysuperwebsite.com/myapp#
这不是我想要的,我需要它而不需要尖锐的字符。
Hi I am using GWT and its standart way to support history via "History" class. It is very convenient but how can I remove anchor part from an url? For example:
My base url:
http://www.mysuperwebsite.com/myapp
While using application I move to a place that adds new history item.
In code:
History.newItem("funnygame");
As result:
http://www.mysuperwebsite.com/myapp#funnygame
I change place one more time:
In code:
History.newItem("notsofunnygames");
As result:
http://www.mysuperwebsite.com/myapp#notsofunnygames
Then I want to go back to my home page (http://www.mysuperwebsite.com/myapp).
What should be placed in code?:
????
to get back to:
http://www.mysuperwebsite.com/myapp
Is there any standart way I can achieve my goal?
If I add something like this:
History.newItem("");
or
History.newItem(null);
the url will become
http://www.mysuperwebsite.com/myapp#
And this is not what I am lloking for, I need it without sharp character.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您使用
History.newItem(null);
将触发一个新事件。结果,您将切换您的主页:
http://www.mysuperwebsite.com/myapp#
末尾有或没有 # 是一回事,我错了吗?
编辑:
If you use
History.newItem(null);
a new event will be fired.As a result, you will toggle your home page :
http://www.mysuperwebsite.com/myapp#
Having or not a # at the end is the same thing, am I wrong ?
EDIT:
该锚点由
#
标识,因此您可以使用以下命令将其删除:The anchor is identified by a
#
, so you can use the following to remove it:如果您不需要历史令牌,您可能错误地使用了历史记录。如果您不打算摆弄导航,我建议使用 GwtEvent / EventHandler。除了将这些事件链接到导航历史记录之外,这本质上就是 gwt 的 History 类所做的事情。
If you dont want a historytoken you are probably using history wrong. If you're not intending to fiddle with navigation i would recommend using GwtEvent / EventHandler. Which is essentially what gwt's History class does, in addition to linking those events to the navigation history.
您可以创建一个工具类,并在 历史改变。
You can create a tool class, and you call it when History changes.