diff --git a/app/components/CharTable.vue b/app/components/CharTable.vue index 6efe6ae..4c14710 100644 --- a/app/components/CharTable.vue +++ b/app/components/CharTable.vue @@ -70,7 +70,7 @@ function turnTo(page: number) { > {{ t('table.page', { - page: Math.min(chars.page.value, chars.pageCount.value), + page: chars.page.value, total: chars.pageCount.value, }) }} diff --git a/app/composables/chars.ts b/app/composables/chars.ts index 08e013f..13e99af 100644 --- a/app/composables/chars.ts +++ b/app/composables/chars.ts @@ -324,11 +324,22 @@ export function useChars() { const pageCount = computed(() => paged.value ? Math.max(1, Math.ceil(rows.value.length / PAGE_SIZE)) : 1, ) - /** Rows on the current page, clamped in case a filter shortened the list. */ + + /** Keep the URL-backed page itself valid, not only the rendered slice. */ + watch( + [page, pageCount, paged], + ([current, total, isPaged]) => { + if (!isPaged) return + const clamped = Math.min(Math.max(1, current), total) + if (current !== clamped) page.value = clamped + }, + { immediate: true, flush: 'sync' }, + ) + + /** Rows on the current page. */ const pageRows = computed(() => { if (!paged.value) return rows.value - const current = Math.min(page.value, pageCount.value) - const start = (current - 1) * PAGE_SIZE + const start = (page.value - 1) * PAGE_SIZE return rows.value.slice(start, start + PAGE_SIZE) })