Vaadin 7 url navigation hashbang

2019-06-14 05:57发布

问题:

I'm trying to fully understand Navigation in Vaadin 7. I read the Navigator Chapter in the Vaadin book but still have some practical questions.

Basically it is about using the bang (!). When do I need to set it and why?

  • There is a view (myview)
  • There is a parameter (param=X)
  • The parameter is identifying a displayed label

Example for browser history:
I need to set the bang (!) or clicking back in the browser does not work, because the parameters is not passed the the views enter function:

private void showInfo(String info) {
    infoLabel.setValue(info);
    Page.getCurrent().setUriFragment("!" + "myview/param=" + info, false);
}

Example for navigation after button click:
I must not set the bang (!) or else the url fragment changes to "#!myview//param=X" (contains double /)

@Override
public void buttonClick(ClickEvent event) {
    getUI().getNavigator().navigateTo("myview/param=X")
}

Am I mixing two concepts here or is there a utility that does that for me and I'm not knowing it? Or do I just have to know about these 2 cases and decide about the bang myself?

Thanks

回答1:

You don't need to set the '!' at all - except you want force your sites to be crawled by search engines (see GoogleDevelopers Spec). Some people even say, these hash bangs are very bad UI practice.

Or is it a requirement for your application that its whole content is indexed by search engines ?