diff --git a/README.md b/README.md
index 0e8e4ea7..09d11fed 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,7 @@ http://it2810-03.idi.ntnu.no/project2/
- **Plant Owner Test:** A short quiz that tells you what kind of plant owner you are. Each result has its own picture, which you can only get through the test, and you can save it as your profile picture.
- **Language:** The app is available in English and Norwegian.
- **Theme:** The app has a light and a dark theme.
+- **Page not found:** Unknown addresses show a 404 page with a link back to Plant Match.
## Tech stack
diff --git a/docs/architecture.md b/docs/architecture.md
index 19a0cd5c..28befe65 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -36,15 +36,16 @@ The sections below describe each part in more detail.
The frontend is built with React and TypeScript (Vite).
-- **Routing:** Routes are defined in `AppRoutes.tsx` with React Router, and the app is served under the base path `/project2/`. Vite defines this base in `frontend/vite.config.ts`; `HashRouter` provides the client-side routes, including Explore query parameters after the hash. All pages except the start page are lazy-loaded.
-
- | Route | Page | Purpose |
- | ----------------- | ---------------- | ----------------------------------------------------------------- |
- | `/` | `PlantMatchPage` | Swipe through plants (`getPlants`), best preference matches first |
- | `/explorePlants` | `ExplorePlants` | Search, filter, sort and paginate all plants (`explorePlants`) |
- | `/my-matches` | `MyMatchesPage` | List and remove the user's matched plants |
- | `/profile` | `Profile` | Edit name, description, profile picture and preferences |
- | `/plantOwnerTest` | `PlantOwnerTest` | A quiz whose result can be set as the profile picture |
+- **Routing:** Routes are defined in `AppRoutes.tsx` with React Router, and the app is served under the base path `/project2/`. Vite defines this base in `frontend/vite.config.ts`; `HashRouter` provides the client-side routes, including Explore query parameters after the hash. All pages except the start page are lazy-loaded. Any path that does not match a route shows the 404 page, and the header shows the "Page not found" title for it.
+
+ | Route | Page | Purpose |
+ | ----------------- | ---------------- | -------------------------------------------------------------- |
+ | `/` | `PlantMatchPage` | Swipe through random plants (`getPlants`) and match with them |
+ | `/explorePlants` | `ExplorePlants` | Search, filter, sort and paginate all plants (`explorePlants`) |
+ | `/my-matches` | `MyMatchesPage` | List and remove the user's matched plants |
+ | `/profile` | `Profile` | Edit name, description, profile picture and preferences |
+ | `/plantOwnerTest` | `PlantOwnerTest` | A quiz whose result can be set as the profile picture |
+ | `*` | `NotFound` | 404 page for unknown paths, with a link back to Plant Match |
- **User state:** `UserProvider` (`context/UserContext.tsx`) loads the current user from the backend and makes it available through `useUser()`. The hooks `useProfile` and `useMatchedPlants` wrap the user mutations, so pages do not call GraphQL directly for user data. All user queries and mutations live in `context/userQueries.ts`.
- **Reusable logic in hooks:** Logic without UI is kept in hooks. `useDebounce` delays updates while the user is typing (used for search and for saving the profile text), `useSearchParams` keeps Explore search, filters, sorting and page in the URL, and `useSessionState` stores state in `sessionStorage` for features that still use it.
diff --git a/docs/quality.md b/docs/quality.md
index 09916052..844aee4f 100644
--- a/docs/quality.md
+++ b/docs/quality.md
@@ -89,3 +89,5 @@ and our approach to data handling.
- **Reusable components:** We used reusable React components to maintain a consistent interface and avoid duplicating code. For example, the Header and Sidebar are shared across pages, while components such as plant cards are used to present plant information consistently. This makes the application easier to maintain and allows changes to be made in one place.
- **Responsive design:** We designed the application for both desktop and mobile screens. The layout adapts to different screen sizes to ensure that the content and navigation remain usable across devices.
+
+- **Page not found:** Unknown addresses show a 404 page instead of a blank page. It links back to Plant Match, and tells the user they can choose another page in the sidebar on desktop or the menu on mobile, so the hint matches the navigation they actually see.
diff --git a/docs/tests.md b/docs/tests.md
index c83c81c4..c8e002e6 100644
--- a/docs/tests.md
+++ b/docs/tests.md
@@ -119,13 +119,15 @@ The tests are in `frontend/src/tests`. Snapshot tests are used for the explore p
- Accessibility: a search landmark, a heading and labelled controls.
- Snapshots of the page with results, with no results and with the sort menu open.
- `Header.test.tsx`
- - Shows the right title for each page, and opens the sidebar with the menu button.
+ - Shows the right title for each page, including the "Page not found" title for unknown paths, and opens the sidebar with the menu button.
- `LanguageSettings.test.tsx`
- Switching language changes the content at once and is kept after a reload, an unsupported saved language falls back to Norwegian, and switching works when browser storage is blocked.
- `LanguageSwitcher.test.tsx`
- The button text and accessible name in both languages, that clicking switches to the other language, and snapshots for both languages.
- `MyMatchesPage.test.tsx`
- A message when there are no matches, the loading state instead of that message, and that saved matches are shown and can be removed.
+- `NotFound.test.tsx`
+ - An unknown path shows the 404 page, with a link back to Plant Match.
- `PlantCard.test.tsx`
- The back of the card shows the whole plant after clicking information, missing facts and images are shown as unknown, and watering, sunlight and care level are turned into the right preference chips.
- `PlantMatchPage.test.tsx`
@@ -238,7 +240,7 @@ Saving the profile is debounced by 800 ms. The test waits until the save request
`uiAccessibility.spec.ts` runs **axe** through `@axe-core/playwright` against WCAG 2.1 level A and AA, the level required for the public sector in Norway. It checks:
-- all five pages (PlantMatch, ExplorePlants, MyMatches, Profile and PlantOwnerTest), in both light and dark mode, since colour contrast has to meet the requirements in both themes
+- all six pages (PlantMatch, ExplorePlants, MyMatches, Profile, PlantOwnerTest and the 404 page), in both light and dark mode, since colour contrast has to meet the requirements in both themes
- content that only appears after an interaction: a flipped plant card, the edit tab on the profile page, MyMatches with a matched plant, and the result of the plant owner test
The tests run on both desktop and mobile, since the layout, and the elements that are visible, differ between them. A failing test lists each element that breaks a rule, with axe's explanation (for contrast: the colours and the ratio).
diff --git a/e2e/uiAccessibility.spec.ts b/e2e/uiAccessibility.spec.ts
index 878d94a2..00628492 100644
--- a/e2e/uiAccessibility.spec.ts
+++ b/e2e/uiAccessibility.spec.ts
@@ -50,6 +50,7 @@ const PAGES = [
path: "#/plantOwnerTest",
loaded: ".plant-owner-test",
},
+ { name: "NotFound", path: "#/does-not-exist", loaded: ".not-found-page" },
];
// Colour contrast is the only check that differs between the themes,
diff --git a/frontend/src/AppRoutes.tsx b/frontend/src/AppRoutes.tsx
index 470cee92..82905aa2 100644
--- a/frontend/src/AppRoutes.tsx
+++ b/frontend/src/AppRoutes.tsx
@@ -10,6 +10,7 @@ const Profile = lazy(() => import("./pages/profile/Profile.tsx"));
const PlantOwnerTest = lazy(
() => import("./pages/plantOwnerTest/PlantOwnerTest.tsx"),
);
+const NotFound = lazy(() => import("./pages/notFound/NotFound.tsx"));
// eslint-disable-next-line react-refresh/only-export-components
export const ROUTES = {
@@ -18,6 +19,7 @@ export const ROUTES = {
myMatches: "/my-matches",
profile: "/profile",
plantOwnerTest: "/plantOwnerTest",
+ notFound: "*",
} as const;
function AppRoutes() {
@@ -29,6 +31,7 @@ function AppRoutes() {
} />
} />
} />
+ } />
);
diff --git a/frontend/src/components/header/Header.tsx b/frontend/src/components/header/Header.tsx
index da90960c..d0ebc0e0 100644
--- a/frontend/src/components/header/Header.tsx
+++ b/frontend/src/components/header/Header.tsx
@@ -14,13 +14,15 @@ const pageTitles: Record = {
[ROUTES.explore]: "sidebar.explorePlants",
[ROUTES.myMatches]: "sidebar.myMatches",
[ROUTES.profile]: "sidebar.profile",
+ [ROUTES.plantOwnerTest]: "sidebar.plantOwnerTest",
};
export default function Header({ isSidebarOpen, onOpenSidebar }: HeaderProps) {
const { t } = useTranslation();
const { pathname } = useLocation();
- const titleKey = pageTitles[pathname] ?? "sidebar.plantMatch";
+ // Paths that are not in pageTitles are shown by the 404 page
+ const titleKey = pageTitles[pathname] ?? "notFound.title";
return (
diff --git a/frontend/src/components/plantCard/PlantCard.tsx b/frontend/src/components/plantCard/PlantCard.tsx
index b40bac11..1863d4d4 100644
--- a/frontend/src/components/plantCard/PlantCard.tsx
+++ b/frontend/src/components/plantCard/PlantCard.tsx
@@ -1,7 +1,7 @@
import { useState } from "react";
import { useTranslation } from "react-i18next";
import "./PlantCard.css";
-import PlantPreferenceChips from "../PlantPreferenceChips/PlantPreferenceChips";
+import PlantPreferenceChips from "../plantPreferenceChips/PlantPreferenceChips";
type Props = {
name: string | null;
diff --git a/frontend/src/components/PlantPreferenceChips/PlantPreferenceChips.css b/frontend/src/components/plantPreferenceChips/PlantPreferenceChips.css
similarity index 100%
rename from frontend/src/components/PlantPreferenceChips/PlantPreferenceChips.css
rename to frontend/src/components/plantPreferenceChips/PlantPreferenceChips.css
diff --git a/frontend/src/components/PlantPreferenceChips/PlantPreferenceChips.tsx b/frontend/src/components/plantPreferenceChips/PlantPreferenceChips.tsx
similarity index 100%
rename from frontend/src/components/PlantPreferenceChips/PlantPreferenceChips.tsx
rename to frontend/src/components/plantPreferenceChips/PlantPreferenceChips.tsx
diff --git a/frontend/src/i18n/locales/en/translation.json b/frontend/src/i18n/locales/en/translation.json
index 4d6388c8..0cce216a 100644
--- a/frontend/src/i18n/locales/en/translation.json
+++ b/frontend/src/i18n/locales/en/translation.json
@@ -174,5 +174,12 @@
"saved": "This is now your profile picture!",
"failed": "Could not save the profile picture. Try again later."
}
+ },
+ "notFound": {
+ "title": "Page not found",
+ "message": "The page you are looking for does not exist.",
+ "backToPlantMatch": "Go to Plant Match",
+ "orChooseInSidebar": "Or choose another page in the sidebar.",
+ "orChooseInMenu": "Or choose another page in the menu."
}
}
diff --git a/frontend/src/i18n/locales/no/translation.json b/frontend/src/i18n/locales/no/translation.json
index 685717d0..f4314a7c 100644
--- a/frontend/src/i18n/locales/no/translation.json
+++ b/frontend/src/i18n/locales/no/translation.json
@@ -174,5 +174,12 @@
"saved": "Dette er nå profilbildet ditt!",
"failed": "Kunne ikke lagre profilbildet. Prøv igjen senere."
}
+ },
+ "notFound": {
+ "title": "Fant ikke siden",
+ "message": "Siden du leter etter finnes ikke.",
+ "backToPlantMatch": "Gå til Plante-Matching",
+ "orChooseInSidebar": "Eller velg en annen side i sidemenyen.",
+ "orChooseInMenu": "Eller velg en annen side i menyen."
}
}
diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx
index a16dc44c..73994d24 100644
--- a/frontend/src/main.tsx
+++ b/frontend/src/main.tsx
@@ -8,14 +8,14 @@ import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client";
import { ApolloProvider } from "@apollo/client/react";
import { UserProvider } from "./context/UserContext.tsx";
-const clienten = new ApolloClient({
+const client = new ApolloClient({
link: new HttpLink({ uri: import.meta.env.VITE_GRAPHQL_URL ?? "/graphql" }),
cache: new InMemoryCache(),
});
createRoot(document.getElementById("root")!).render(
-
+
diff --git a/frontend/src/pages/notFound/NotFound.css b/frontend/src/pages/notFound/NotFound.css
new file mode 100644
index 00000000..a62a0553
--- /dev/null
+++ b/frontend/src/pages/notFound/NotFound.css
@@ -0,0 +1,72 @@
+.not-found-page {
+ margin-left: var(--sidebar-width);
+ width: calc(100% - var(--sidebar-width));
+ min-height: 60vh;
+ padding: 40px;
+ box-sizing: border-box;
+
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ gap: 1rem;
+ text-align: center;
+ font-family: Georgia, serif;
+}
+
+.not-found-code {
+ margin: 0;
+ font-size: 4rem;
+ color: var(--pink-text);
+}
+
+.not-found-message {
+ margin: 0;
+ font-size: 1.25rem;
+ color: var(--text-dark);
+}
+
+.not-found-link {
+ padding: 0.5rem 1rem;
+ border: 1px solid var(--dark-pink);
+ border-radius: 8px;
+ background-color: var(--light-background);
+ color: var(--text-dark);
+ text-decoration: none;
+}
+
+.not-found-link:hover {
+ background-color: var(--dark-pink);
+ color: var(--text-light);
+}
+
+.not-found-link:focus-visible {
+ outline: none;
+ box-shadow: 0 0 0 2px var(--dark-pink);
+}
+
+.not-found-hint {
+ margin: 0;
+ font-size: 1.25rem;
+ color: var(--text-dark);
+}
+
+.not-found-hint--mobile {
+ display: none;
+}
+
+@media (max-width: 767px) {
+ .not-found-page {
+ margin-left: 0;
+ width: 100%;
+ padding: 20px;
+ }
+
+ .not-found-hint--desktop {
+ display: none;
+ }
+
+ .not-found-hint--mobile {
+ display: block;
+ }
+}
diff --git a/frontend/src/pages/notFound/NotFound.tsx b/frontend/src/pages/notFound/NotFound.tsx
new file mode 100644
index 00000000..b72885c5
--- /dev/null
+++ b/frontend/src/pages/notFound/NotFound.tsx
@@ -0,0 +1,26 @@
+import { Link } from "react-router-dom";
+import { useTranslation } from "react-i18next";
+import { ROUTES } from "../../AppRoutes";
+import "./NotFound.css";
+
+// Shown for every path that does not match a route in AppRoutes
+export default function NotFound() {
+ const { t } = useTranslation();
+
+ return (
+
+
404
+
{t("notFound.message")}
+
+ {t("notFound.backToPlantMatch")}
+
+ {/* Desktop shows the sidebar, mobile has a menu button, so the hint differs */}
+
+ {t("notFound.orChooseInSidebar")}
+
+
+ {t("notFound.orChooseInMenu")}
+
+
+ );
+}
diff --git a/frontend/src/tests/Header.test.tsx b/frontend/src/tests/Header.test.tsx
index 7293b4c3..f7c3f3c5 100644
--- a/frontend/src/tests/Header.test.tsx
+++ b/frontend/src/tests/Header.test.tsx
@@ -24,7 +24,8 @@ describe("Header", () => {
[ROUTES.explore, "sidebar.explorePlants"],
[ROUTES.myMatches, "sidebar.myMatches"],
[ROUTES.profile, "sidebar.profile"],
- ["/unknown-page", "sidebar.plantMatch"],
+ [ROUTES.plantOwnerTest, "sidebar.plantOwnerTest"],
+ ["/unknown-page", "notFound.title"],
])("shows the title for %s", (route, title) => {
renderHeader(route);
diff --git a/frontend/src/tests/NotFound.test.tsx b/frontend/src/tests/NotFound.test.tsx
new file mode 100644
index 00000000..c0dfea63
--- /dev/null
+++ b/frontend/src/tests/NotFound.test.tsx
@@ -0,0 +1,24 @@
+import { render, screen } from "@testing-library/react";
+import { MemoryRouter } from "react-router-dom";
+import { describe, it, expect, vi } from "vitest";
+import AppRoutes, { ROUTES } from "../AppRoutes";
+
+vi.mock("react-i18next", () => ({
+ useTranslation: () => ({ t: (key: string) => key }),
+}));
+
+describe("NotFound", () => {
+ it("is shown for an unknown path and links back to PlantMatch", async () => {
+ render(
+
+
+ ,
+ );
+
+ // The page is lazy loaded, so findBy waits until it is shown
+ expect(await screen.findByText("notFound.message")).toBeInTheDocument();
+ expect(
+ screen.getByRole("link", { name: "notFound.backToPlantMatch" }),
+ ).toHaveAttribute("href", ROUTES.plantMatch);
+ });
+});