deal with territory case using clientside redirect
This commit is contained in:
parent
26e0dd6f7e
commit
29a8640493
@ -8,6 +8,7 @@ import { WelcomeBanner } from '../../components/banners'
|
|||||||
import { useQuery } from '@apollo/client'
|
import { useQuery } from '@apollo/client'
|
||||||
import PageLoading from '../../components/page-loading'
|
import PageLoading from '../../components/page-loading'
|
||||||
import TerritoryHeader from '../../components/territory-header'
|
import TerritoryHeader from '../../components/territory-header'
|
||||||
|
import { useEffect } from 'react'
|
||||||
|
|
||||||
export const getServerSideProps = getGetServerSideProps({
|
export const getServerSideProps = getGetServerSideProps({
|
||||||
query: SUB_ITEMS,
|
query: SUB_ITEMS,
|
||||||
@ -22,6 +23,16 @@ export default function Sub ({ ssrData }) {
|
|||||||
if (!data && !ssrData) return <PageLoading />
|
if (!data && !ssrData) return <PageLoading />
|
||||||
const { sub } = data || ssrData
|
const { sub } = data || ssrData
|
||||||
|
|
||||||
|
// basically a client-side redirect to the canonical url
|
||||||
|
useEffect(() => {
|
||||||
|
if (sub?.name && sub?.name !== router.query.sub) {
|
||||||
|
router.replace({
|
||||||
|
pathname: router.pathname,
|
||||||
|
query: { ...router.query, sub: sub.name }
|
||||||
|
}, `/~${sub.name}`)
|
||||||
|
}
|
||||||
|
}, [sub?.name])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout sub={variables.sub}>
|
<Layout sub={variables.sub}>
|
||||||
{sub
|
{sub
|
||||||
|
Loading…
x
Reference in New Issue
Block a user