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

How to exclude some routes when using nuxt generate #2719

Closed
SzHeJason opened this issue Jan 30, 2018 · 7 comments
Closed

How to exclude some routes when using nuxt generate #2719

SzHeJason opened this issue Jan 30, 2018 · 7 comments
Labels

Comments

@SzHeJason
Copy link

SzHeJason commented Jan 30, 2018

current router

 page
 --- about.vue
 --- index.vue

I just want to generate an about HTML file when using nuxt generate, how can I do that?

This question is available on Nuxt.js community (#c2362)
@microcipcip
Copy link

you just create a page named about.vue right there

@dan-peterson
Copy link

Do you want only a subset of your pages generated when you run nuxt generate?

I was wanting to do the same thing today. My solution was to use a custom module to leverage the internal plugin system (Note that in the latest releases these are now called hooks and have been re-worked a bit. They don't appear to be documented yet.)

I'm not sure if this is the best approach but it certainly seems to do the trick for now.

modules/custom-generate.js

module.exports = function () {
  this.nuxt.hook('generate:extendRoutes', async routes => {
    const whiteList = ['/about', '/login'];
    const routesToGenerate = routes.filter(page => whiteList.includes(page.route));
    routes.splice(0, routes.length, ...routesToGenerate);
  });
};

nuxt.config.js

modules: [
  '~modules/custom-generate.js'
],

@dan-peterson
Copy link

dan-peterson commented Feb 28, 2018

@qm3ster Good point. I think the only catch is that generate.routes only gives you control over dynamic routes. If you want to blacklist some static routes from generate, you still need the extendRoutes hook, or is there a better way?

@SzHeJason
Copy link
Author

I tried but it did not work

 generate: {
    routes: ["about"]
  },

How to setting generate.routes make nuxt disables route autogeneration ? Can you show the code?

Nuxt Version : 1.3.0

@qm3ster qm3ster changed the title How to exclude some router when using nuxt generate How to exclude some routes when using nuxt generate Mar 3, 2018
@qm3ster
Copy link

qm3ster commented Mar 3, 2018

@dan-peterson @SzHeJason I was wrong, this has been changed a gorillion months ago.
The generate.routes are now merged with autodetected routes.
generate:extendRoutes seems like the only way now.

@lock
Copy link

lock bot commented Nov 3, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 3, 2018
@manniL
Copy link
Member

manniL commented Jul 4, 2019

For all googlers, this is possible via regex in generate.exclude. if the route URL matches the regex, the page will be excluded from generating but can still be served as "SPA route".

See #4754

@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants