Next.js Discord

Discord Forum

Custom 404 page causing hard navigation

Unanswered
Labrador Retriever posted this in #help-forum
Open in Discord
Labrador RetrieverOP
I get this error “Error: Invariant: attempted to hard navigate to the same URL /information localhost:3000/information” when using a custom 404 page

next.config
    rewrites() {
        return {
            fallback: [
                {
                    source: "/:path*",
                    destination: "/404bug?path=:path*",
                    locale: false,
                },
            ],
        };
    },

404bug.js
const BugFixer = () => null;
export default BugFixer;
export const getServerSideProps = () => ({ notFound: true });


middleware.js
import { NextResponse } from "next/server";
export async function middleware(req) {
    // some code
    return NextResponse.next();
}


In v14.1.4 it worked fine

https://github.com/vercel/next.js/compare/v14.1.4...v14.2.6

1 Reply