Is it possible to define which routes are rendered fully server-side and which are served in SPA mode?
The use-case I am thinking of is I have a small "marketing" area including a homepage which need to be search engine crawlable so ssr is a must. The majority of the site would be hidden behind authentication, so the added overhead of ssr is unnecessary for these areas.
Thanks for any tips!
Hi @gridsystem . Actually, This is available under an experimental feature from rc5.
The current way is using express/connect middleware before SSR to set a spa = true flag on specific routes to disable SSR on them (We still need SSR bundle for all routes so nuxt should be running in universal mode). So using serverMiddleware:
module.exports = {
path: '/public',
handler(req, res, next) {
res.spa = true
next()
}
}
Actual implementation code: https://github.com/nuxt/nuxt.js/blob/7738d0c0af958a715f5ca2fde8f95be81832ca42/lib/core/renderer.js#L451
Please let me know how things go for you about this :)
Thanks @pi0 your example and link will be very useful.
Is there a changelog somewhere (other than the commit log) for rc5?
@gridsystem The feature is not stable and well tested, for now. So documenting of many features like dynamic spa is intentionally postponed. We may investigate more to see if this would handle all needs or not.
@gridsystem I'll close this issue making off topic for easier maintenance of new issues. Feel free to reopen or pinging me if any further help was needed.
Regards.
Thank you @pi0 . The code is very helpful, I ended up using the following code in nuxt.config.js:
module.exports = {
...,
serverMiddleware: [
{ path: '/event', handler: (req, res, next) => { res.spa = true; next() } }
]
}
This is working for me in the Dev mode. But when I did generate, there is a reference error, which is that window is not defined. Why this config not work after generate.
Thanks.
I fixed it with using require. if (process.browser) { var a = require(a) }
But it is really cool, if we can do this in config file.
@pi0 Thanks for all your great work,
Is this feature tested or documented yet?
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.