2

I have a page that has a table that has Pagination and tabs. Url Looks something like this.

http://localhost:4000/listPage?tab=all&page=1&items=10

So I want to update the URL state(query params) every time user paginates and changes tabs without reloading the page only making requests to API's.

Same for changing the tab. Update the query params without reloading the page.

I have tried using the history.pushState but this will mess with vue-router history and clicking back and forward will no longer take you to the correct page.

history.pushState(
            {},
            null,
            this.$route.path + '?'
            + 'view=' + this.currentView + '&'
            + 'page=' + this.currentPage + '&'
            + 'items=' + this.items
          );
1

1 Answer 1

-1

This should be enough to solve your case

<button 
  @click="$router.replace({ 
    path: $route.path,
    query: { tab: 'all', page: 1, items: 10 } 
  })"
>
  paginate without moving
</button>

More info available here: https://router.vuejs.org/guide/essentials/navigation.html#navigate-to-a-different-location

Sign up to request clarification or add additional context in comments.

2 Comments

This doesn't work, router.replace causes reload/remounting of components
@Krillko OP mentions only page reload, which this is NOT doing (only updating the Vue router), it is meanwhile indeed impact components' lifecycle. My answer is then correct and you are probably looking for another question overall.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.