nuxt/nuxt

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

Open

#24174 opened on Nov 7, 2023

View on GitHub
 (6 comments) (0 reactions) (0 assignees)TypeScript (60,221 stars) (5,607 forks)batch import
good first issue🍰 p2-nice-to-have🛠️ dx

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