Next.js Discord

Discord Forum

Builded app not-found link works wrongly sometimes

Unanswered
Bartholomeas posted this in #help-forum
Open in Discord
[NextJS Question]

In development everything is ok, but when i build my app i cannot get back to homepage sometmes.

I mean: I have page "delivery" that is statically generated but i doesnt have page for that (so when user goes to delivery url it gets not-found 404 page) and then user have button "Back to home" but when he clicks it it doesnt move him, it just removes part of url and keeps one slash for some reason.

Otherwise when i go to wrong url in my shop/productslug page everything is working correctly.

Idk how to spot that, tottaly no idea..

Heres code of my component that handles that: (Just common <Link/> component )

"use client";

import React from "react";
import Link from "next/link";
import { routes } from "@/misc/routes";
import { Button, Card, Heading, SectionLeafs, Text, buttonVariants } from "@/components/common";

interface ErrorCardProps {
  errorCode: string | number;
  errorMessage: string;
  onClick?: () => void;
}

const ErrorCard = ({
  errorCode = 500,
  errorMessage = "Wystąpił nieznany błąd.",
  onClick,
}: ErrorCardProps) => {
  return (
    <Card className="relative flex flex-col items-center gap-4">
      <SectionLeafs position="top" direction="left" />
      <SectionLeafs position="bottom" direction="right" />
      <Heading
        type="h1"
        className="inline h-fit pb-10 text-[100px]"
        color="neutral-700"
        weight="bold"
      >
        {errorCode}
      </Heading>
      <Text size="lg" color="neutral-900">
        {errorMessage}
      </Text>
      {onClick ? (
        <Button onClick={onClick}>Spróbuj ponownie</Button>
      ) : (
        <Link className={buttonVariants({})} href={routes["index"]} as={routes["index"]}>
          Powrót do strony głównej
        </Link>
      )}
    </Card>
  );
};

export default ErrorCard;

0 Replies