Skip to content

Commit

Permalink
Merge pull request #210 from mobeigi/fix-broken-redirects
Browse files Browse the repository at this point in the history
Call payloadRedirect from both generateMetadata and handler
  • Loading branch information
mobeigi authored Oct 28, 2024
2 parents fcb7eb4 + 68d2ad7 commit 5df9cb7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/src/app/(frontend)/[...catchAll]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export const generateMetadata = async ({
};

// Any route that isn't handled by other routes will end up here
const CatchAllHandler = () => {
const CatchAllHandler = async ({ params: paramsPromise }: { params: Promise<{ catchAll: string[] }> }) => {
const params = await paramsPromise;
await payloadRedirect({ currentUrl: joinUrl([...params.catchAll]) });
notFound();
};

Expand Down
2 changes: 2 additions & 0 deletions app/src/app/(frontend)/blog/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ export const generateStaticParams = async () => {
const BlogPostHandler = async ({ params: paramsPromise }: { params: Promise<{ slug: string[] }> }) => {
const params = await paramsPromise;

await payloadRedirect({ currentUrl: joinUrl(['blog', ...params.slug]) });

const post = await getPayloadPostFromParams({ params });
if (!post) {
notFound();
Expand Down
3 changes: 2 additions & 1 deletion app/src/app/(frontend)/blog/category/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const revalidate = 900;
/**
* Data fetching
*/

const getPayloadCategoryFromParams = ({ params }: { params: { slug: string[] } }) =>
unstable_cache_safe(
async (): Promise<PayloadCategory | null> => {
Expand Down Expand Up @@ -218,6 +217,8 @@ export const generateStaticParams = async () => {
const CategoryDetailPageHandler = async ({ params: paramsPromise }: { params: Promise<{ slug: string[] }> }) => {
const params = await paramsPromise;

await payloadRedirect({ currentUrl: joinUrl(['blog', 'category', ...params.slug]) });

const payloadCategory = await getPayloadCategoryFromParams({ params });
if (!payloadCategory) {
notFound();
Expand Down

0 comments on commit 5df9cb7

Please sign in to comment.