From 12731b7fcb2d57a8286be4dafd8184bbdf52894a Mon Sep 17 00:00:00 2001 From: Alexandra Date: Thu, 29 Oct 2026 11:40:21 +0100 Subject: [PATCH] Use HashRouter so refreshing a subpage on the VM no longer gives 404 Apache has no fallback to index.html, so paths like /project2/explorePlants returned 404 on refresh. With HashRouter the route is after the #, so Apache always serves /project2/. E2e tests now navigate with #/ paths. Co-Authored-By: Claude Opus 5.5 --- e2e/uiAccessibility.spec.ts | 18 +++++++++--------- e2e/uiExplorePlants.spec.ts | 2 +- e2e/uiMatchAndRemovePlant.spec.ts | 2 +- e2e/uiUserProfile.spec.ts | 2 +- frontend/src/main.tsx | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/e2e/uiAccessibility.spec.ts b/e2e/uiAccessibility.spec.ts index 85e5a50c..b9ed05ea 100644 --- a/e2e/uiAccessibility.spec.ts +++ b/e2e/uiAccessibility.spec.ts @@ -38,12 +38,12 @@ async function setTheme(page: Page, theme: "light" | "dark") { // Each page and an element that shows the page has finished loading const PAGES = [ { name: "PlantMatch", path: "", loaded: ".plant-card-front" }, - { name: "ExplorePlants", path: "explorePlants", loaded: ".plant-grid > li" }, - { name: "MyMatches", path: "my-matches", loaded: ".matches-grid" }, - { name: "Profile", path: "profile", loaded: "main.profile" }, + { name: "ExplorePlants", path: "#/explorePlants", loaded: ".plant-grid > li" }, + { name: "MyMatches", path: "#/my-matches", loaded: ".matches-grid" }, + { name: "Profile", path: "#/profile", loaded: "main.profile" }, { name: "PlantOwnerTest", - path: "plantOwnerTest", + path: "#/plantOwnerTest", loaded: ".plant-owner-test", }, ]; @@ -69,7 +69,7 @@ for (const theme of THEMES) { test.describe("after interaction", () => { test("ExplorePlants with a plant card flipped", async ({ page }) => { - await page.goto("explorePlants"); + await page.goto("#/explorePlants"); const firstCard = page.locator(".plant-grid > li").first(); await firstCard .locator(".plant-card-front .plant-card-info-button") @@ -82,7 +82,7 @@ test.describe("after interaction", () => { }); test("Profile with the edit tab open", async ({ page }) => { - await page.goto("profile"); + await page.goto("#/profile"); await page .getByRole("button", { name: /edit profile|endre profil/i }) .click(); @@ -92,7 +92,7 @@ test.describe("after interaction", () => { test("MyMatches with a matched plant", async ({ page }) => { // A new user has no matches, so add one from ExplorePlants first - await page.goto("explorePlants"); + await page.goto("#/explorePlants"); const addButton = page .locator(".plant-grid > li") .first() @@ -100,13 +100,13 @@ test.describe("after interaction", () => { await addButton.click(); await expect(addButton).toBeDisabled(); - await page.goto("my-matches"); + await page.goto("#/my-matches"); await expect(page.locator(".plant-card-match")).toHaveCount(1); await checkAccessibility(page); }); test("PlantOwnerTest showing a result", async ({ page }) => { - await page.goto("plantOwnerTest"); + await page.goto("#/plantOwnerTest"); const options = page.locator(".plant-owner-test-option"); const nextButton = page diff --git a/e2e/uiExplorePlants.spec.ts b/e2e/uiExplorePlants.spec.ts index ee0a8334..4dc2cee2 100644 --- a/e2e/uiExplorePlants.spec.ts +++ b/e2e/uiExplorePlants.spec.ts @@ -18,7 +18,7 @@ test("user pages, filters, searches, opens a plant, sorts and resets", async ({ const nextButton = pagination.getByRole("button").last(); await test.step("the first page shows 12 plants sorted a–z", async () => { - await page.goto("explorePlants"); + await page.goto("#/explorePlants"); await expect(cards).toHaveCount(12); await expect(cards.first()).toContainText("Aloe Vera"); await expect(previousButton).toBeDisabled(); diff --git a/e2e/uiMatchAndRemovePlant.spec.ts b/e2e/uiMatchAndRemovePlant.spec.ts index 41b44458..5b7854f4 100644 --- a/e2e/uiMatchAndRemovePlant.spec.ts +++ b/e2e/uiMatchAndRemovePlant.spec.ts @@ -38,7 +38,7 @@ test("user can like a plant in PlantMatch, find it in MyMatches and remove the m test("user can add a plant from ExplorePlants and find it in MyMatches", async ({ page, }) => { - await page.goto("explorePlants"); + await page.goto("#/explorePlants"); // The first plant sorted a–z is always Aloe Vera in the fixtures const firstCard = page.locator(".plant-grid > li").first(); diff --git a/e2e/uiUserProfile.spec.ts b/e2e/uiUserProfile.spec.ts index 44126be4..fe0b0f74 100644 --- a/e2e/uiUserProfile.spec.ts +++ b/e2e/uiUserProfile.spec.ts @@ -24,7 +24,7 @@ test("user can update profile and avatar, and navigate between pages", async ({ const chosenAvatar = page.locator("button.avatar-option").first(); await test.step("user edits name, description and avatar", async () => { - await page.goto("profile"); + await page.goto("#/profile"); // The edit form is only shown in the "Edit profile" tab await editProfileTab.click(); diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index 32a2d483..a16dc44c 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -1,6 +1,6 @@ import { StrictMode } from "react"; import { createRoot } from "react-dom/client"; -import { BrowserRouter } from "react-router-dom"; +import { HashRouter } from "react-router-dom"; import "./index.css"; import "./i18n"; import App from "./App.tsx"; @@ -17,9 +17,9 @@ createRoot(document.getElementById("root")!).render( - + - + ,