Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom routes with nuxt extends not working #1837

Closed
memic84 opened this issue Feb 1, 2023 · 5 comments
Closed

Custom routes with nuxt extends not working #1837

memic84 opened this issue Feb 1, 2023 · 5 comments

Comments

@memic84
Copy link

memic84 commented Feb 1, 2023

Environment

  • Operating System: Darwin
  • Node Version: v16.14.2
  • Nuxt Version: 3.1.1
  • Nitro Version: 2.1.1
  • Package Manager: [email protected]
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-starter-5ar22s?file=nuxt.config.ts,base%2Fnuxt.config.ts,base%2Froutes%2FRoutes.js,pages%2Findex.vue

Describe the bug

When the extends functionality from Nuxt 3 is used, and we have a pages directory when is extended into the source. The pages inside the extend are not found by the i18n module.

The pages inside the root work fine. I am on the latest version (8.0.0-beta.9)

You'll see in the reproduction that there is a login and register to showcase this.

The login.vue is located inside the extend base directory, and is not found, also the terminal gives a warning: [@nuxtjs/i18n]: Couldn't find AnalizedNuxtPageMeta by NuxtPage (/login), so no custom route for it

The register.vue is located inside the root, and works fine.

Additional context

If this is something that needs to be fixed in Nuxt 3, is there a workaround for this?

Also you can see what's wrong on the homepage, where the link for login is referring to /login and not /aanmelden, as it is set in routes/Routes.js

It might be a bit related to: #1743, however this is not really a RFC.

Logs

No response

@memic84
Copy link
Author

memic84 commented Feb 17, 2023

Any news on this? Or can you point me in a direction to fix this?

@shinesoftware
Copy link

Any news about this issue?! Our project is stucked into it!

@memic84
Copy link
Author

memic84 commented Mar 7, 2023

Any news about this issue?! Our project is stucked into it!

Until this is resolved, you could just not use the pages as extend or create duplicate files.

But yeah we are too stuck with this. I'll try to open a PR if i find a solution.

@memic84
Copy link
Author

memic84 commented Mar 10, 2023

@kazupon I have tried to fix this issue, but got kinda stuck to find the right direction of the fix.

The problem here is that in src/pages.ts the pagesDir doesn't use the directory from the defined layers.

const pagesDir = nuxt.options.dir && nuxt.options.dir.pages ? nuxt.options.dir.pages : 'pages'

What i tried is to add the payers to the pagesDir, but that mean that i'll have to define the pagesDir as an array, which will break the rest of the code ofcourse.

This is what i tried:

  const pagesDir: string[] = []

  if (nuxt.options._layers && nuxt.options._layers.length > 1) {
    interface NuxtLayer {
      config: never
      configFile: string
      cwd: string
    }

    const layers = nuxt.options._layers as NuxtLayer[]
    for (const layer of layers) {
      pagesDir.push(layer.cwd)
    }
  } else {
    pagesDir.push(nuxt.options.dir && nuxt.options.dir.pages ? nuxt.options.dir.pages : 'pages')
  }

As i see it we have two options:

  1. Adapt the code, to work with a pagesDir array
  2. Is it possible to execute, or hook in... with te setup function after the layers directories already have been merged.

@memic84
Copy link
Author

memic84 commented Mar 31, 2023

Resolved with: #1925

@memic84 memic84 closed this as completed Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants