|
| 1 | +/* |
| 2 | + * Copyright (C) 2025 Dimitrios S. Sfyris |
| 3 | + * SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | + */ |
| 5 | +import React, { useEffect } from "react"; |
| 6 | +import { Link, useNavigate } from "react-router-dom"; |
| 7 | +import { APP_NAME, SUPPORT_EMAIL } from "../lib/config"; |
| 8 | + |
| 9 | +function setMeta(name, content) { |
| 10 | + let tag = document.querySelector(`meta[name="${name}"]`); |
| 11 | + if (!tag) { |
| 12 | + tag = document.createElement("meta"); |
| 13 | + tag.setAttribute("name", name); |
| 14 | + document.head.appendChild(tag); |
| 15 | + } |
| 16 | + tag.setAttribute("content", content); |
| 17 | +} |
| 18 | + |
| 19 | +export default function NotFound() { |
| 20 | + const navigate = useNavigate(); |
| 21 | + |
| 22 | + useEffect(() => { |
| 23 | + const prevTitle = document.title; |
| 24 | + document.title = `404 — Page Not Found | ${APP_NAME}`; |
| 25 | + setMeta("robots", "noindex,follow"); |
| 26 | + setMeta( |
| 27 | + "description", |
| 28 | + "The page you’re looking for was not found. Explore products, learn about us, or contact support." |
| 29 | + ); |
| 30 | + return () => { |
| 31 | + document.title = prevTitle; |
| 32 | + }; |
| 33 | + }, []); |
| 34 | + |
| 35 | + const path = |
| 36 | + typeof window !== "undefined" ? window.location.pathname : "/nonexistent"; |
| 37 | + const subject = `Broken link: ${path}`; |
| 38 | + const mailto = `mailto:${encodeURIComponent( |
| 39 | + SUPPORT_EMAIL |
| 40 | + )}?subject=${encodeURIComponent(subject)}`; |
| 41 | + |
| 42 | + return ( |
| 43 | + <div className="mx-auto max-w-4xl p-6"> |
| 44 | + <div className="rounded-2xl border border-neutral-200 bg-white p-8 shadow-card"> |
| 45 | + <p className="text-sm tracking-wide text-neutral-500">Error 404</p> |
| 46 | + <h1 className="mt-1 font-display text-3xl font-semibold text-ink"> |
| 47 | + We couldn’t find that page |
| 48 | + </h1> |
| 49 | + <p className="mt-2 text-neutral-600"> |
| 50 | + The requested address{" "} |
| 51 | + <code className="rounded bg-neutral-100 px-1 py-0.5">{path}</code>{" "} |
| 52 | + doesn’t exist. It might have been moved or the link could be |
| 53 | + incorrect. |
| 54 | + </p> |
| 55 | + |
| 56 | + <div className="mt-6 grid gap-3 sm:flex"> |
| 57 | + <button |
| 58 | + onClick={() => navigate(-1)} |
| 59 | + className="inline-flex items-center justify-center rounded-xl border border-neutral-300 px-4 py-2 text-ink hover:bg-neutral-50" |
| 60 | + > |
| 61 | + Go back |
| 62 | + </button> |
| 63 | + <Link |
| 64 | + to="/" |
| 65 | + className="inline-flex items-center justify-center rounded-xl bg-ink px-4 py-2 text-white hover:bg-neutral-900" |
| 66 | + > |
| 67 | + Go to homepage |
| 68 | + </Link> |
| 69 | + <Link |
| 70 | + to="/product" |
| 71 | + className="inline-flex items-center justify-center rounded-xl bg-neutral-900/80 px-4 py-2 text-white hover:bg-neutral-900" |
| 72 | + > |
| 73 | + Browse products |
| 74 | + </Link> |
| 75 | + <Link |
| 76 | + to="/contact" |
| 77 | + className="inline-flex items-center justify-center rounded-xl border border-neutral-300 px-4 py-2 text-ink hover:bg-neutral-50" |
| 78 | + > |
| 79 | + Contact us |
| 80 | + </Link> |
| 81 | + </div> |
| 82 | + |
| 83 | + <div className="mt-8"> |
| 84 | + <h2 className="text-sm font-semibold uppercase tracking-wide text-neutral-500"> |
| 85 | + Popular destinations |
| 86 | + </h2> |
| 87 | + <ul className="mt-3 grid gap-2 sm:grid-cols-2"> |
| 88 | + <li> |
| 89 | + <Link |
| 90 | + className="block rounded-lg border border-neutral-200 p-3 hover:bg-neutral-50" |
| 91 | + to="/product" |
| 92 | + > |
| 93 | + Shop / Products |
| 94 | + </Link> |
| 95 | + </li> |
| 96 | + <li> |
| 97 | + <Link |
| 98 | + className="block rounded-lg border border-neutral-200 p-3 hover:bg-neutral-50" |
| 99 | + to="/about" |
| 100 | + > |
| 101 | + About |
| 102 | + </Link> |
| 103 | + </li> |
| 104 | + <li> |
| 105 | + <Link |
| 106 | + className="block rounded-lg border border-neutral-200 p-3 hover:bg-neutral-50" |
| 107 | + to="/cart" |
| 108 | + > |
| 109 | + Your cart |
| 110 | + </Link> |
| 111 | + </li> |
| 112 | + <li> |
| 113 | + <Link |
| 114 | + className="block rounded-lg border border-neutral-200 p-3 hover:bg-neutral-50" |
| 115 | + to="/login" |
| 116 | + > |
| 117 | + Sign in |
| 118 | + </Link> |
| 119 | + </li> |
| 120 | + </ul> |
| 121 | + </div> |
| 122 | + |
| 123 | + <p className="mt-6 text-xs text-neutral-500"> |
| 124 | + If you believe this is a broken link, please{" "} |
| 125 | + <a className="underline hover:no-underline" href={mailto}> |
| 126 | + report it to {SUPPORT_EMAIL} |
| 127 | + </a> |
| 128 | + . |
| 129 | + </p> |
| 130 | + </div> |
| 131 | + </div> |
| 132 | + ); |
| 133 | +} |
0 commit comments