vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
620 stars 167 forks source link

Document why the hash string shouldn't be used for navigation #2742

Open vlukashov opened 7 years ago

vlukashov commented 7 years ago

When handling a navigation event, as a developer, I want to get the URL fragment of the current URL (i.e. the edit part of the /orders/12#edit URL).

With the new Router API that is not supported at the moment (flow-1.0.0.alpha6). There is no getFragment() method:

@Override
public void afterNavigation(AfterNavigationEvent event) {
    String fragment = event.getLocation().getFragment();
}
Artur- commented 7 years ago

This is quite logical as the fragment is a browser side feature only. IMO it should be used for its real purpose (link anchors) and not for navigation (contrary to how Navigator works in Framework 8).

The main reason is that the fragment is not sent to the server automatically so it is not available in the initial request.

vlukashov commented 7 years ago

That's a valid argument, but I would not give it too much weight since Flow is already relaying so many of other browser-only entities to the server, that adding another once does not change the big picture.

In this ticket I am saying is that as a developer I want to use fragments for switching between different states of my views. I assume there are other developers out there who will want the same.

If that's not implemented, please consider adding a compelling explanation into the docs why it's possible in Angular / Vue / React apps but now in Flow.

knoobie commented 7 years ago

As I understand Flow correctly, you want to change from being a SPA to a full blown web-page-framework. While doing that, it would be a huge step in the wrong direction to use the # again.

For example it can be quite handy to bookmark a specific position on a long page. (www.example.com/docs/4.0/headings#h5)

Why not use something like the old fashioned Query String?

pleku commented 7 years ago

I would say fragments should not be used in this use case at all. Not sure why Vue or Angular or something else thinks that it is a valid case now, since there is a history API and everything, unlike when the FW navigation was done when it was not yet supported for all browsers, and thus #fragment was the best option.

Legioth commented 7 years ago

I fully agree with the concerns expressed by various commenters. Using # for navigation is an outdated pattern from the times before all browsers supported the History API. The main reason for still using it would be to preserve legacy URLs and bookmarks.

We might still want to mention the reasoning in some suitable part of the documentation, but I don't think we should implement any direct support.