Skip to content

Commit 8c7e639

Browse files
author
Gareth Redfern
committed
refactor pagination, if no path don’t change router
1 parent d6a99bb commit 8c7e639

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/components/BasePagination.vue

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default {
5858
},
5959
path: {
6060
type: String,
61-
required: true,
61+
default: null,
6262
},
6363
meta: {
6464
type: Object,
@@ -72,34 +72,42 @@ export default {
7272
methods: {
7373
firstPage() {
7474
this.$store.dispatch(this.action, this.links.first).then(() => {
75-
this.$router.push({
76-
path: this.path,
77-
query: { page: 1 },
78-
});
75+
if (this.path) {
76+
this.$router.push({
77+
path: this.path,
78+
query: { page: 1 },
79+
});
80+
}
7981
});
8082
},
8183
prevPage() {
8284
this.$store.dispatch(this.action, this.links.prev).then(() => {
83-
this.$router.push({
84-
path: this.path,
85-
query: { page: this.meta.current_page - 1 },
86-
});
85+
if (this.path) {
86+
this.$router.push({
87+
path: this.path,
88+
query: { page: this.meta.current_page - 1 },
89+
});
90+
}
8791
});
8892
},
8993
nextPage() {
9094
this.$store.dispatch(this.action, this.links.next).then(() => {
91-
this.$router.push({
92-
path: this.path,
93-
query: { page: this.meta.current_page + 1 },
94-
});
95+
if (this.path) {
96+
this.$router.push({
97+
path: this.path,
98+
query: { page: this.meta.current_page + 1 },
99+
});
100+
}
95101
});
96102
},
97103
lastPage() {
98104
this.$store.dispatch(this.action, this.links.last).then(() => {
99-
this.$router.push({
100-
path: this.path,
101-
query: { page: this.meta.last_page },
102-
});
105+
if (this.path) {
106+
this.$router.push({
107+
path: this.path,
108+
query: { page: this.meta.last_page },
109+
});
110+
}
103111
});
104112
},
105113
},

0 commit comments

Comments
 (0)