Skip to content

Commit

Permalink
Merge pull request #2278 from graphcommerce-org/fix/redirects-blog
Browse files Browse the repository at this point in the history
[fix/redirects-blog] fix redirects on blog pages
  • Loading branch information
paales authored Jun 5, 2024
2 parents db3340c + 74eaab0 commit 49d4a4a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions examples/magento-graphcms/pages/blog/[...url].tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PageOptions } from '@graphcommerce/framer-next-pages'
import { hygraphPageContent, HygraphPagesQuery } from '@graphcommerce/graphcms-ui'
import { StoreConfigDocument } from '@graphcommerce/magento-store'
import { redirectOrNotFound, StoreConfigDocument } from '@graphcommerce/magento-store'
import {
PageMeta,
BlogTitle,
Expand Down Expand Up @@ -93,7 +93,9 @@ export const getStaticProps: GetPageStaticProps = async ({ locale, params }) =>
query: BlogListDocument,
variables: { currentUrl: [`blog/${urlKey}`], first: limit },
})
if (!(await page).data.pages?.[0]) return { notFound: true }

if (!(await page).data.pages?.[0])
return redirectOrNotFound(staticClient, conf, { url: `blog/${urlKey}` }, locale)

return {
props: {
Expand Down
6 changes: 4 additions & 2 deletions examples/magento-graphcms/pages/blog/tagged/[url].tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PageOptions } from '@graphcommerce/framer-next-pages'
import { hygraphPageContent, HygraphPagesQuery } from '@graphcommerce/graphcms-ui'
import { StoreConfigDocument } from '@graphcommerce/magento-store'
import { redirectOrNotFound, StoreConfigDocument } from '@graphcommerce/magento-store'
import { PageMeta, GetStaticProps, Row, LayoutTitle, LayoutHeader } from '@graphcommerce/next-ui'
import { i18n } from '@lingui/core'
import { Trans } from '@lingui/react'
Expand Down Expand Up @@ -90,7 +90,9 @@ export const getStaticProps: GetPageStaticProps = async ({ locale, params }) =>
query: BlogListTaggedDocument,
variables: { currentUrl: [`blog/tagged/${urlKey}`], first: limit, tagged: params?.url },
})
if (!(await page).data.pages?.[0]) return { notFound: true }

if (!(await page).data.pages?.[0])
return redirectOrNotFound(staticClient, conf, { url: `blog/${urlKey}` }, locale)

return {
props: {
Expand Down
4 changes: 2 additions & 2 deletions examples/magento-graphcms/pages/service/[[...url]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
hygraphPageContent,
HygraphPagesQuery,
} from '@graphcommerce/graphcms-ui'
import { StoreConfigDocument } from '@graphcommerce/magento-store'
import { StoreConfigDocument, redirectOrNotFound } from '@graphcommerce/magento-store'
import { PageMeta, GetStaticProps, LayoutOverlayHeader, LayoutTitle } from '@graphcommerce/next-ui'
import { i18n } from '@lingui/core'
import { Container } from '@mui/material'
Expand Down Expand Up @@ -84,7 +84,7 @@ export const getStaticProps: GetPageStaticProps = async ({ locale, params }) =>
const page = hygraphPageContent(staticClient, url)
const layout = staticClient.query({ query: LayoutDocument, fetchPolicy: 'cache-first' })

if (!(await page).data.pages?.[0]) return { notFound: true }
if (!(await page).data.pages?.[0]) return redirectOrNotFound(staticClient, conf, { url }, locale)

const isRoot = url === 'service'

Expand Down

0 comments on commit 49d4a4a

Please sign in to comment.