Redirect to contract page if home loads initially with query params
This commit is contained in:
parent
ff1cb68077
commit
4268e03293
|
@ -31,15 +31,16 @@ const Home = () => {
|
||||||
)
|
)
|
||||||
|
|
||||||
const router = useRouter()
|
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)
|
const contract = feedContracts.find((c) => c.slug === slug)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (slug && !contract) {
|
// If the page initially loads with query params, redirect to the contract page.
|
||||||
delete router.query.c
|
if (router.isReady && slug && username) {
|
||||||
router.replace(router, undefined, { shallow: true })
|
Router.replace(`/${username}/${slug}`)
|
||||||
}
|
}
|
||||||
})
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [router.isReady])
|
||||||
|
|
||||||
if (user === null) {
|
if (user === null) {
|
||||||
Router.replace('/')
|
Router.replace('/')
|
||||||
|
@ -59,7 +60,9 @@ const Home = () => {
|
||||||
recentBets={recentBets}
|
recentBets={recentBets}
|
||||||
recentComments={recentComments}
|
recentComments={recentComments}
|
||||||
mode="only-recent"
|
mode="only-recent"
|
||||||
getContractPath={(c) => `home?c=${c.slug}`}
|
getContractPath={(c) =>
|
||||||
|
`home?u=${c.creatorUsername}&s=${c.slug}`
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<LoadingIndicator className="mt-4" />
|
<LoadingIndicator className="mt-4" />
|
||||||
|
|
Loading…
Reference in New Issue
Block a user