I following this sample : Updating URL Parameters without Navigation | Routing & Navigation | Flow | Vaadin Docs
So I create one combobox and when the user select one item I update the url just like the sample… But I have 2 problems.
First is that I have my afterNavigation method executed everty time that I change the url. and the second is that method (and the setParameter are executed 2 time) every time I try to update the url.
In the sample says
// Assign the full deep linking URL directly using
// History object: changes the URL in the browser,
// but doesn’t reload the page.
So if he dont reload, the correct are don’t execute the afterNavigation correct?
This is an expected behavior ?
have an way to don’t execute the afterNavigation?
I need to use QueryParameters so change my url to /my-view?filter=a&sort=b
tks
1 Like
Tatu2
(Tatu Lund)
August 22, 2024, 1:06pm
2
It is simply a bug.
See the reports:
opened 01:02PM - 21 Aug 24 UTC
bug
BFP
Impact: Low
Severity: Major
### Description of the bug
I previously raised https://github.com/vaadin/flow/i… ssues/19701 with a minimal reproducible example. That example was fixed but our actual use case requires a slightly more complicated reproducible example which I have attached to this ticket.
This issue is stopping us from being able to upgrade to 24.4
The example provided uses replaceState to update the URL. I think the issue also occurs when using forwarding. We switched to replaceState due to an earlier issue with PreserveOnRefresh which meant forwarding did not update the URL. Now neither mechanism works in this scenario.
launch the app with:
mvn jetty:run
Navigate to:
http://localhost:8080/parent/?blah=blah
You will find that the URL changes to:
http://localhost:8080/parent/child?blah=blah
but the desired outcome is that the URL changes to:
http://localhost:8080/parent/child?corrected=true
In ChildRoute.java you can delete the @PreserveOnRefresh and then repeat the test and it will work as desired.
Also, when @PreserveOnRefresh is enabled, you will see that you get two beforeEnter callbacks in ChildRoute but without it enabled, you get 1 as expected.
### Expected behavior
replaceState should update the URL in all instances
### Minimal reproducible example
[preserveonrefresh-issue2.zip](https://github.com/user-attachments/files/16691794/preserveonrefresh-issue2.zip)
### Versions
- Vaadin / Flow version: 24.4.x (tested on 24.4.9)
opened 01:34PM - 17 Jul 24 UTC
closed 08:20AM - 24 Jul 24 UTC
bug
BFP
workaround
Impact: Low
Severity: Minor
preserve-on-refresh
navigation
prerelease version for Vaadin 24.5.0
Released with Vaadin 24.5.0.alpha6
Released with Vaadin 24.4.8
### Description of the bug
In my repro example there is a route called TreeView… ("/tree"). It contains 3 buttons. If you click the first button it navigated to /tree?param=one. If you click the second, it navigates to /tree?param=two etc.
My demo app has @PreserveOnRefresh on the TreeView route. When clicking the buttons, the URL does not update.
If you remove @PreserveOnRefresh, the buttons do cause the URL to update.
The actual navigation is fine but the URL does not change correctly.
We had previously worked around this by calling ui.getPage().getHistory().replaceState(..) to set the correct URL. However, we are now unable to upgrade to 24.4 due to https://github.com/vaadin/flow/issues/19613
I don't really want to be calling replaceState so I'd like to get this bug fixed so we don't have to.
### Expected behavior
URL should change when the buttons are pressed
### Minimal reproducible example
[preserveonrefresh-nav-issue.zip](https://github.com/user-attachments/files/16266332/preserveonrefresh-nav-issue.zip)
### Versions
- Vaadin / Flow version: 24.4 (was present in 23)
- Java version: 17
- OS version: osx
opened 08:54AM - 20 Jun 24 UTC
closed 07:57AM - 09 Aug 24 UTC
bug
BFP
Impact: Low
Severity: Major
navigation
react
Released with Vaadin 24.4.9
### Description of the bug
When using React router, History#pushState and #re… placeState trigger navigation event (trigger HISTORY, coming from a dom event "ui-navigate"). Even if only query parameters are changed.
With Flow Router, no navigation event occurs, not matter which part of the path has changed.
May relate to
* #19580 Also has something to do with breaking behavior change in History#replaceState with React Router
* #19540 Also has something to do with undesired navigation event
* #19494 Also has something to do with undesired HISTORY navigation event if the target URL does not exactly match the current one
* #19539 This sounds like a similar fix, but only applied to pushState. Indeed, pushState work as Flow Router and also as I would expect.
### Expected behavior
No navigation events on History#pushState and #replaceState. If a navigation event is desired, I would use UI.navigate.
### Minimal reproducible example
I modified the example from a comment in #19580
```
@Route(value = "test/:path?")
public class TestView extends VerticalLayout implements BeforeEnterObserver, BeforeLeaveObserver {
public TestView() {
add(new Button("replace state - no query params",
event -> UI.getCurrent().getPage().getHistory().replaceState(null, "test")));
// no navigation only if the current URL is the same including query params
add(new Button("replace state - push query param",
event -> UI.getCurrent().getPage().getHistory().replaceState(null, "test?new")));
// no navigation only if the current URL is the same including query params
add(new Button("replace state - change path param",
event -> UI.getCurrent().getPage().getHistory().replaceState(null, "test/new")));
// no navigation only if the current URL is the same including query params
add(new Button("push state - no query params",
event -> UI.getCurrent().getPage().getHistory().pushState(null, "test")));
// no navigation
add(new Button("push state - query param",
event -> UI.getCurrent().getPage().getHistory().pushState(null, "test?new")));
// no navigation
add(new Button("push state - change path param",
event -> UI.getCurrent().getPage().getHistory().pushState(null, "test/new")));
// no navigation
}
@Override
public void beforeEnter(BeforeEnterEvent event) {
add(new Div("beforeEnter"));
}
@Override
public void beforeLeave(BeforeLeaveEvent beforeLeaveEvent) {
add(new Div("beforeLeave"));
}
}
```
### Versions
- Vaadin / Flow version: 24.4.3
- Java version: 17
- OS version: Windows
- Browser version (if applicable):
- Application Server (if applicable): Spring Boot
- IDE (if applicable):
2/3 are fixed. So if you update the latest version, your app may already work. If not wait for the last one to be fixed.