Skip to content

Commit

Permalink
fix: 🐛 show not found when deployed
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy-guzman committed Oct 29, 2024
1 parent 6fa1ce4 commit 5f1dcfa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions e2e/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ test("has title", async ({ page }) => {
await expect(page).toHaveTitle(/React Starter/);
});

test("not found", async ({ page }) => {
await page.goto("/lost");

await expect(page).toHaveTitle(/React Starter/);

await expect(
page.getByRole("heading", { name: "Error", level: 1 }),
).toBeInViewport();
});

test.describe("external links", () => {
test.beforeEach(async ({ page }) => {
await page.goto("/");
Expand Down
1 change: 1 addition & 0 deletions src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const router = createRouter({
routeTree,
defaultNotFoundComponent: NotFound,
defaultErrorComponent: Error,
notFoundMode: "root",
});

declare module "@tanstack/react-router" {
Expand Down
7 changes: 6 additions & 1 deletion src/routes/__root.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createRootRouteWithContext, Outlet } from "@tanstack/react-router";
import { lazy, Suspense } from "react";

import { NotFound } from "@/pages/not-found";

const RouterDevTools = import.meta.env.DEV
? lazy(async () => {
return import("@tanstack/router-devtools").then((res) => {
Expand All @@ -24,4 +26,7 @@ const Root = () => {
);
};

export const Route = createRootRouteWithContext()({ component: Root });
export const Route = createRootRouteWithContext()({
component: Root,
notFoundComponent: NotFound,
});

0 comments on commit 5f1dcfa

Please sign in to comment.