From c40bd5f645a40027fdaad30158e86b05356e8506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9B=90=EB=8D=94?= Date: Wed, 27 Jan 2021 14:32:52 +0900 Subject: [PATCH] fix: page query validation --- pages/list/votes.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pages/list/votes.tsx b/pages/list/votes.tsx index 1ece754..d336b55 100644 --- a/pages/list/votes.tsx +++ b/pages/list/votes.tsx @@ -7,14 +7,16 @@ import * as Query from '@utils/Query' import NotFound from '../404' import { PageCount } from '@utils/Yup' +import { useRouter } from 'next/router' const Advertisement = dynamic(()=> import('@components/Advertisement')) const BotCard = dynamic(()=> import('@components/BotCard')) const Container = dynamic(()=> import('@components/Container')) const Paginator = dynamic(()=> import('@components/Paginator')) -const Votes:NextPage = ({ data }:VotesProps) => { - if(!data || data.data.length === 0) return +const Votes:NextPage = ({ data }) => { + const router = useRouter() + if(!data || data.data.length === 0 || data.totalPage < Number(router.query.page)) return return

하트 랭킹 - {data.currentPage}페이지 @@ -30,9 +32,11 @@ const Votes:NextPage = ({ data }:VotesProps) => { } export const getServerSideProps = async (ctx:Context) => { + let data: BotList + if(!ctx.query.page) ctx.query.page = '1' const validate = await PageCount.validate(ctx.query.page).then(el => el).catch(() => null) - if(isNaN(Number(ctx.query.page)) || !validate) ctx.query.page = '1' - const data = await Query.get.list.votes.load(Number(ctx.query.page)) + if(!validate) data = null + else data = await Query.get.list.votes.load(Number(ctx.query.page)) return { props: { data