Is it possible to change url using vue-router without going to the page?

Viewed 1169

There is a shop on nuxtjs and on the /catalog page I need to make a "Load more" button. By clicking on it, products should be loaded and the url should be changed to /catalog/page_2 (?page=2 is not suitable). If I change the url through $router.push nuxt goes to this page, but I need to change the url, but not go anywhere. Is it possible to somehow undo the reloading but save the changes in the url?

history.pushState copes with the task, but in this case nuxt does not know that the url has changed and when clicking forward / backward in the browser nuxt does not load the goods needed for this page

2 Answers

Paginations logically belong to the main page so It's good to consider them in URL queries, like ?page=2. also you can use router.replace to change queries.

this.$router.replace({
        query: { ...this.$route.query, page: this.page},
      })
Related