Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT. Remove anchor part url

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.

like image 726
Zalivaka Avatar asked Jan 31 '11 10:01

Zalivaka


2 Answers

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:

  ...
  // Get the last part of the url and remove #token
  String s = Location.getHref().substring(Location.getHref().lastIndexOf("/"));
  s = s.substring(0, s.indexOf("#")-1);
  setToken(s);
  ...

  protected native void setToken(String token) /*-{
    $wnd.history.pushState({},'', token);
}-*/;
like image 199
Naoj Avatar answered Oct 12 '22 23:10

Naoj


The anchor is identified by a #, so you can use the following to remove it:

int index = link.indexOf('#');
if (index != -1) {
    link = link.substring(0, index);
}
like image 32
dogbane Avatar answered Oct 12 '22 23:10

dogbane