Friday, April 10, 2015

pushstate - having trouble updating url without reloading page

I have been reading, researching, and trying to integrate a quick solution to take advantage of HTML5 pushstate in my current app. I have briefly looked at the gwt-pushstate project which I am impressed with and I may consider for the future, but right now I just need to get it working. I have looked at this on stack overflow to try to mimic what Manolo suggests, I have even explored the gwtproject.org source code. The problem is strangely this, it is working perfectly on IE10 which I know is really weird. Every other browser I have tried, IE11 and the latest Chrome reloads the page. I feel like I am missing something simple and perhaps very obvious, I am hoping a second pair of eyes can easily see what I am doing wrong.

My project uses an MVP pattern and I still have the standard GWT url pattern with the # in it. In my view I have what I call sub views that I want to navigate to and update the url for the benefits of history flow. It is all in the same Place and in my case this logically makes since. When I click on a navigation menu item I want to update the url as I reveal the sub view UI. My current url pattern is something like this: 
http://127.0.0.1:8888/?gwt.codesvr=127.0.0.1:9997#StandardView:parameter1&viewType=SomeSubView

The "viewType=SomeSubView" is the part that will change. In the future I would like to enhance the url to look better, I know it is a bit ugly but just trying to get working, then improve from there. When I click a navigation menu item to go to a new sub view this is my code that uses pushstate:

void push( String subView ){
     String pageUrl = "#StandardView:parameter1&viewType="+subView;

     // Preserve QueryString, useful for the gwt.codesvr parameter in dev-mode.
     pageUrl = pageUrl.replaceFirst("(#.*|)$", Window.Location.getQueryString() + "$1");
     
     // Set the page to load in the URL
     Properties history = JsUtils.prop(window, "history");
     JsUtils.runJavascriptFunction(history, "pushState", null, null, pageUrl);
}

So now can someone help me figure out what I am doing wrong. It is just really weird that IE10 works with this.

Thanks,
Will

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment