Nuxt.js: Ability to prevents page generation in `generate:page`

Created on 30 May 2020  路  5Comments  路  Source: nuxt/nuxt.js

What problem does this feature solve?

What if we can add a single boolean to the page variable to conditionally control page generation?

https://github.com/nuxt/nuxt.js/blob/c14471681c7134a6a08a69f9eabdb7d213feb2f0/packages/generator/src/generator.js#L361-L373

What does the proposed changes look like?

// Call hook to let user update the path & html
    const page = { route, path: fileName, html, generate: true }
    await this.nuxt.callHook('generate:page', { page, errors: pageErrors })
    await this.nuxt.callHook('export:page', { page })

    if (page.generate) {
        page.path = path.join(this.distPath, page.path)
        ...
    }

    return page.generate

Or for being fully backward compatible we could use export:page hook:

    const page = { route, path: fileName, html, generate: true }
...
    await this.nuxt.callHook('export:page', { page, errors: pageErrors })

    if (page.generate) {
...

This feature request is available on Nuxt community (#c10713)
contributions welcome feature-request

Most helpful comment

You mean to generate a single page? I'm not sure I understand your request.

The idea is to exclude pages from generation "on the fly" by using the return value of a nuxt hook instead of using generate.excludes

All 5 comments

You mean to generate a single page? I'm not sure I understand your request.

You mean to generate a single page? I'm not sure I understand your request.

The idea is to exclude pages from generation "on the fly" by using the return value of a nuxt hook instead of using generate.excludes

I think it would be a nice idea to leverage export:page hook for excluding page generation (maybe also being able to set ssr/spa? :see_no_evil: Use case: Marking any route matching /checkout/ SPA even with crawler)

I think it would be a nice idea to leverage export:page hook for excluding page generation (maybe also being able to set ssr/spa? 馃檲 Use case: Marking any route matching /checkout/ SPA even with crawler)

Would this allow mixing static and SSR pages? Should be quiet useful, if you want some pages (e.g. your blog) to be static and the rest of your site to be dynamically rendered by the server.

I think it would be a nice idea to leverage export:page hook for excluding page generation (maybe also being able to set ssr/spa? 馃檲 Use case: Marking any route matching /checkout/ SPA even with crawler)

Would this allow mixing static and SSR pages? Should be quiet useful, if you want some pages (e.g. your blog) to be static and the rest of your site to be dynamically rendered by the server.

Nope, that's not the scope of this feature.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattdharmon picture mattdharmon  路  3Comments

surmon-china picture surmon-china  路  3Comments

danieloprado picture danieloprado  路  3Comments

pehbehbeh picture pehbehbeh  路  3Comments

msudgh picture msudgh  路  3Comments