nuxt / nuxt/nuxt

warn if `pages:extend` adds a route which replaces an existing route

Open
#24,174 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🍰 p2-nice-to-have 🛠️ dx good first issue
Dominant language
TypeScript
Stars
60.9k
Forks
5.8k
Avg merge
7h 8m
Merged PRs (30d)
162

Description

Environment
  • Operating System: Linux
  • Node Version: v18.15.0
  • Nuxt Version: 3.8.0
  • CLI Version: 3.9.1
  • Nitro Version: 2.7.0
  • Package Manager: pnpm@8.7.6
  • Builder: -
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -
Reproduction
  1. Starts a module following https://nuxt.com/docs/guide/going-further/modules
  2. Create a page in src/runtime/pages/test.vue (module);
<template><h1>Page from module</h1></template>
  1. Register the page in src/module.ts:
extendPages((pages) => {
      pages.push({
        name: 'test',
        path: '/test',
        file: resolver.resolve('runtime', 'pages', 'test'),
      })
    })
  1. Create a page in playground/pages/test.vue (playground):
<template><h1>Page from playground</h1></template>
  1. Start the project
  2. Navigate to http://localhost:3000/test
Describe the bug

The "Page from module" is displayed instead of the "Page from playground"

Additional context

Replacing pages.push with pages.unshift effectively displays the "playground" pages.

Using a different name (than the "generated one") in module such as: name: 'mymodule-test' fixes this but declares two pages (while the former re-group? both pages) in dev tools.

There is no warning or whatsoever that this page is declared twice.

As this is called extendPages I would expect this to not override project pages.

In my case I wan't to be able to "override" module pages from playground pages.

Logs

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the extendPages callback in src/module.ts and reproduce the conflict using the module and playground pages described in the issue. Trace how the pages array handles duplicate names and paths; done means a duplicate route replacement is reported with a warning while the intended route behavior is clear.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxt, typescript
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.