# Add a 404 Page to a Vue Router App

Yes. An agent adds a catch-all route and a NotFound view to a Vue 3 app, sends a missing article there without changing the URL, tests it and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-not-found-page/vue/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the router before it adds a route. In an app shaped like realworld-apps/vue-realworld-example-app, `package.json` pins `vue` ^3.5, `vue-router` ^5.1, `pinia` ^3 and `vite` ^8, with `@playwright/test` ^1.60, `eslint` and `prettier` for development, installed with `bun`; the scripts are `serve`, `build`, `lint`, `format:check` and `test:e2e`. `src/router/index.js` declares ten named routes, `home`, `home-tag`, `login`, `register`, `settings`, `profile`, `profile-favorites`, `article`, `editor-new` and `article-edit`, each as a lazy `import()` of a view without the `.vue` extension, which `vite.config.js` allows through `resolve.extensions`, and `meta.requiresAuth` on the settings and editor routes. There is no catch-all, so an unknown URL renders `App.vue`'s header and footer around an empty `router-view`. `src/main.js` registers a `router.beforeEach` that awaits `auth.checkAuth()` and redirects to `/login` when a guarded route is hit without a session. `src/views/Article.vue` fetches the article and its comments in `beforeRouteEnter` through the Pinia article store and swallows a failure with `.catch(() => null)`, so a missing slug renders the page with an empty article. `src/views/Login.vue` shows the view style: `defineOptions({ name: 'RwvLogin' })`, Conduit markup from the `realworld` submodule's theme, `script setup`.

It adds `src/views/NotFound.vue` in that style: `RwvNotFound`, a `container page` with a heading, the path that was requested, and a `router-link` to `home`. `src/router/index.js` gets a last entry named `not-found` on `/:pathMatch(.*)*`, lazily importing the view like the others and without `requiresAuth`, so the guard in `main.js` lets it through once `checkAuth()` has resolved. `Article.vue` stops swallowing a 404: `beforeRouteEnter` keeps tolerating a comments failure, but when `fetchArticle` rejects with `error.response.status` of 404 it returns the `not-found` route with `pathMatch` set from `to.path`, so the address bar keeps the article URL and the user sees the 404 view instead of an empty banner. Other failures still render as before. The header stays as it is, and nothing in the auth store changes.

`playwright.config.ts` points `testDir` at `./realworld/specs/e2e`, the shared suite in the submodule, and starts `bun run serve` on `127.0.0.1:8080`. The agent does not edit the submodule; it adds `e2e/not-found.spec.ts` in the repository and a second `projects` entry in `playwright.config.ts` with `testDir: './e2e'`, so the shared suite runs unchanged beside the new file. The spec visits a made-up path and expects the heading and the home link, visits `/article/no-such-article` and expects the same heading with the URL unchanged, and visits a guarded path while signed out to confirm the redirect to `/login` still wins. It runs `bun run lint` and `bun run format:check`, the two steps in `.github/workflows/lint.yml`, `bun run build`, and `bunx playwright install --with-deps chromium` followed by `bun run test:e2e` as `.github/workflows/playwright.yml` does, and pastes the output in the pull request.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add a 404 page to this Vue 3 app and open a pull request. Read package.json, vite.config.js, src/main.js, src/App.vue, src/router/index.js, src/views/Login.vue, src/views/Article.vue, src/store/article.js, src/common/api.service.js, playwright.config.ts and the two workflows under .github/workflows first. Add src/views/NotFound.vue named RwvNotFound in the style of Login.vue with a heading, the requested path and a router-link to home. Add a last route named not-found on /:pathMatch(.*)* that lazily imports it, with no requiresAuth. In Article.vue's beforeRouteEnter, when fetchArticle rejects with a 404, return the not-found route with pathMatch built from to.path so the URL stays; keep other failures as they are. Add e2e/not-found.spec.ts and a second Playwright project with testDir ./e2e, leaving the realworld submodule suite untouched, covering an unknown path, a missing article with the URL unchanged, and a guarded path still redirecting to /login. Run bun run lint, bun run format:check, bun run build and bun run test:e2e and paste the output in the pull request. Do not change the header, the auth store or the submodule.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request that adds `src/views/NotFound.vue` and `e2e/not-found.spec.ts`, edits `src/router/index.js`, `src/views/Article.vue` and `playwright.config.ts`, and leaves `main.js`, the header and the stores alone. The description shows the three Playwright cases and pastes the `eslint`, `prettier`, `vite build` and Playwright output.

On a repository with the `Format Check` and `Playwright Tests` workflows, the pull request runs the lint steps and the end-to-end suite with the submodule checked out, so the new project runs beside the shared specs.

A reviewer checks that the catch-all is the last route, that the article redirect only fires on a 404 and not on a network failure, that the requested path is rendered as text, and that a signed-out visit to a guarded URL still lands on the login page. Then they decide whether the server or CDN should answer unknown paths with a real 404 status.

## Run it on every Vue app with a bare router

A team with several Vue front ends sends one `POST /o/{org}/sessions` per repository with this prompt and that repository in `resources`. Each run reads its own router, so an app on `createWebHashHistory` gets the same catch-all and an app with nested layouts gets the view inside the right parent, and each run opens its own pull request.

Give the API key a `webhook_url` and Rush POSTs `run.completed` when each turn ends, with the `session_url` to read the pull request and the test output from.

## Why run it on Rush?

A 404 page is only right in the browser: the catch-all must lose to every real route, the guard must still redirect, and a missing article must land on the page without rewriting the address. In a Rush sandbox the agent starts the Vite server, drives the three cases through Playwright in Chromium and keeps the output in the run's record, so the pull request shows the behaviour rather than describing it.

The change is one view, one route entry and one branch in `beforeRouteEnter`, in the shapes the app already uses, so there is no dependency and nothing to configure. The same request works on any Vue 3 app on `vue-router`.

## Frequently asked questions

### Does an unknown URL return a real 404 status?

Not from the app; a single-page app answers every path with the same `index.html` and the router decides what to render. The view is the 404 the user sees. A real status needs the host to map unknown paths, and the pull request notes that as a deployment step.

### Why keep the URL when an article is missing?

So the address bar still shows what was asked for and a reload or a bookmark behaves the same. `beforeRouteEnter` returns the `not-found` route with `pathMatch` set from the original path, which renders the view without a redirect in the history.

### Does the catch-all interfere with the auth guard?

No. The guard in `main.js` runs on every navigation and only redirects routes with `requiresAuth` or the following feed. The `not-found` route has no such flag, so it renders for signed-in and signed-out visitors alike.

### Why a second Playwright project instead of a new spec in the suite?

The suite lives in the `realworld` submodule, which the repository tracks by commit and does not edit. A second project with its own `testDir` runs the repository's own spec beside the shared ones under the same `webServer`.

## More Vue jobs

- [Add Optimistic UI to a Vue App](https://getrush.ai/run/add-optimistic-ui/vue/)
- [Add Page Titles per Route to a Vue App](https://getrush.ai/run/add-page-titles/vue/)
- [Persist Pinia State in a Vue App from a Linear Issue](https://getrush.ai/run/add-pinia-persistence/vue/)

## The same job on other stacks

- [Add a Not Found Page to an Angular App](https://getrush.ai/run/add-not-found-page/angular/)
- [Add a Custom 404 Page to a React Router App](https://getrush.ai/run/add-not-found-page/react-router/)
- [Add a 404 Page to a SolidJS App](https://getrush.ai/run/add-not-found-page/solidjs/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
