Repository navigation
Updating a page's route query, with a signal. #548
|
Is there a way to update the route query of a page without reloading the page? |
Replies: 1 comment 4 replies
|
yes if the signal already filters the gallery you only need to sync the address bar in its change handler using const url = new URL(window.location.href);
url.searchParams.set("c", value);
history.replaceState(history.state, "", url);this updates the shareable url without fetching or reloading the page and preserves other query parameters it does not automatically update the signal when navigating back so keep that distinction in mind if you choose pushState instead |
yes wrap the statements in an immediately invoked function so the whole thing is one expression my earlier example missed that wrapper
your second version changes one URL object then passes a fresh unchanged object to replaceState this keeps the same object throughout i checked the javascript expression and preservation of other query parameters in node but have not run the topcoat app