Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit b161747

Browse files
author
Greg Rickaby
authored
Merge pull request #106 from WebDevStudios/feature/33-post-archive-page-redirect
Feature/33 post archive page redirect
2 parents 6b02ab6 + 3131a00 commit b161747

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

api/wordpress/pages/queryPageById.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const queryPageById = gql`
2525
) {
2626
page(id: $id, idType: $idType) {
2727
...SinglePageFields
28+
isPostsPage
2829
}
2930
}
3031
${singlePageFragment}

pages/[...slug].js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ export default function Page({post}) {
4747
/>
4848
</article>
4949
</section>
50-
{post.slug === 'form-demo' && <BlockGravityForm {...post?.blocks[0]} />}
50+
{post?.slug === 'form-demo' && (
51+
<BlockGravityForm {...post?.blocks[0]} />
52+
)}
5153
</div>
5254
</Layout>
5355
)

pages/_app.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import '@/styles/index.css'
33
import {ApolloProvider} from '@apollo/client'
44
import {DefaultSeo} from 'next-seo'
55
import Error from 'next/error'
6-
import {useState} from 'react'
6+
import {useState, useEffect} from 'react'
77
import PropTypes from 'prop-types'
88
import AlgoliaProvider from '@/components/common/AlgoliaProvider'
99
import MenuProvider from '@/components/common/MenuProvider'
10+
import {useRouter} from 'next/router'
1011

1112
/**
1213
* Render the App component.
@@ -25,6 +26,17 @@ export default function App({Component, pageProps}) {
2526
*/
2627
const apolloClient = useApollo(pageProps)
2728

29+
const router = useRouter()
30+
31+
// Redirect from WP blog archive to FE posts archive.
32+
useEffect(() => {
33+
if (!pageProps?.post?.isPostsPage) {
34+
return
35+
}
36+
37+
router.push('/blog')
38+
}, [pageProps, router])
39+
2840
// Check for errors.
2941
const error = pageProps?.error
3042
let errorMessage = pageProps?.errorMessage ?? 'An unknown error occurred.'

0 commit comments

Comments
 (0)