Next.js Discord

Discord Forum

Search params in url throws page not found. Nextjs 14 app dir

Unanswered
Romanian Mioritic Shepherd Dog posted this in #help-forum
Open in Discord
Avatar
Romanian Mioritic Shepherd DogOP
Hello, I am trying to have a page with params in the url, but it keeps throwing a page not found when there are params present. When there are not params present, the page loads fine with the content.
This is what I have in my page.tsx file:
const Page = ({
  searchParams,
}: {
  searchParams: { plan: Plan; state: string; code: string };
}) => {
  console.log("MainAgencyPage searchParams: ", searchParams);
  return (
    <div className="flex justify-center items-center mt-4">
      <div className="max-w-[850px] border-[1px] p-4 rounded-xl">
        <h1 className="text-4xl"> Create An Agency</h1>
      </div>
    </div>
  );
};

export default Page;


Would appreciate any help thank you!
Image

5 Replies

Avatar
not-milo.tsx
What does the layout look like?
Avatar
Romanian Mioritic Shepherd DogOP
This is my layout for my (main) group, which the agency page is in:

import { auth } from "@/auth";
import { SessionProvider } from "next-auth/react";
import React from "react";

export default async function layout({
  children,
}: Readonly<{ children: React.ReactNode }>) {
  const session = await auth();
  return <SessionProvider session={session}>{children}</SessionProvider>;
}


And this is my root layout:
export default async function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en" suppressHydrationWarning>
      <body className={font.className}>
        <ThemeProvider
          attribute="class"
          defaultTheme="system"
          enableSystem
          disableTransitionOnChange
        >
          <ClientLayout>{children}</ClientLayout>
          <Toaster />
          <SonnarToaster position="top-center" richColors />
        </ThemeProvider>
      </body>
    </html>
  );
}
Avatar
not-milo.tsx
Ok, you're using next-auth, so you must have a middleware file that manages redirections.
There must be something happening there that's causing 404 responses on pages that exist.

Your page.tsx and layout.tsx don't have anything wrond as far as I can tell.
Avatar
Romanian Mioritic Shepherd DogOP
Yes, thank you so much for help! I did find something wrong in my middleware that was causing this.
Avatar
not-milo.tsx
Glad to hear you fixed it ✌🏻