I have an working pagination,using (Laravel,Vuejs and Bootstrap-Vue), but I need to add the page number in url to use history. (for back button). That's what I have till now. The goal is place page nr. in url,to have a back button.
{
path: "/", //here I will change it with "/:id"
name: "Home",
component: Home,
},
<b-pagination
v-model="currentPage"
:per-page="perPage"
:total-rows="totalRows"
>
</b-pagination> //this is my pagination nav, that takes currentPage from get Request
axios.get('/list',{
params: {
'page': this.currentPage,
'per_page': this.perPage,
},
})
.then(response => {
this.perPage = response.data.per_page;
this.totalRows = response.data.total;
})
.catch(function (error) {
console.log('Error');
}) //and this is the get request
Update
I add router.push({ path: "/", query: { page: this.currentPage } });
on my get response. I have the path ,but when I try to access page 2 , the id it'changed in 2, and in 1 again. and I got an error of duplicate.
NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated", message: "Navigating to current location ("/?page=1") is not allowed"
UPDATE 2 I almost made it, the only thing that don't work yet is active class, on pagination, always page 1 is active. (content,url and currentPage variable are changed)
watch:{
currentPage() {
this.$router
.push({
query: {
...this.$route.query,
page: this.currentPage
}
})
.catch(() => {});
},
}
//In reseponse from axios:
this.currentPage = response.data.current_page;