From 4268e0329363b4dd49db65199fbd3c7e6dae843e Mon Sep 17 00:00:00 2001 From: James Grugett Date: Tue, 12 Apr 2022 23:11:10 -0500 Subject: [PATCH] Redirect to contract page if home loads initially with query params --- web/pages/home.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/web/pages/home.tsx b/web/pages/home.tsx index cf097d54..d593935c 100644 --- a/web/pages/home.tsx +++ b/web/pages/home.tsx @@ -31,15 +31,16 @@ const Home = () => { ) const router = useRouter() - const slug = router.query.c as string | undefined + const { u: username, s: slug } = router.query const contract = feedContracts.find((c) => c.slug === slug) useEffect(() => { - if (slug && !contract) { - delete router.query.c - router.replace(router, undefined, { shallow: true }) + // If the page initially loads with query params, redirect to the contract page. + if (router.isReady && slug && username) { + Router.replace(`/${username}/${slug}`) } - }) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [router.isReady]) if (user === null) { Router.replace('/') @@ -59,7 +60,9 @@ const Home = () => { recentBets={recentBets} recentComments={recentComments} mode="only-recent" - getContractPath={(c) => `home?c=${c.slug}`} + getContractPath={(c) => + `home?u=${c.creatorUsername}&s=${c.slug}` + } /> ) : (