Closed atinux closed 2 years ago
Really nice proposal here @Atinux !
Could we simply omit this.$ctx.params
& this.$ctx.query
?
I mean, Is there any advantage besides having 2-characters shorter behavior than through this.$route
?
You are right, I re-read it this morning and was like: This is USELESS 😄
Thanks @kevinmarrec, I updated the RFC
Looks really cool. Maybe also interesting to take into account that the new async data can work with prefetching.
Will env variables still be set in nuxt.config.js?
export default ({ app, ctx, nuxt }) {
}
+1 for this.
With the new
asyncData
supportingthis
, we won't need the context to be given as argument.Here's my proposal:
After talking with Pooya, I agree to remove
env
from the context since it's misleading and environment variables have a clear definition and use case for operating system. Also, since it's build with Webpack it can lead to secure informations leaked to client if misused.App specific
this.$ctx.req
on server (mock on client && process.static to throw an error)this.$ctx.res
on server (mock on client && process.static to throw an error)this.$ctx.from
===this.$route
before navigation (this.$ctx.$from
===this.$route
on server)this.$ctx.route
(since we addmeta
property)Nuxt specific
this.$nuxt.state
===window.__NUXT__
on client &ssrContext.nuxt.state
on serverthis.$nuxt.redirect()
this.$nuxt.error()
this.$nuxt.inject()
used in plugins, used to inject inthis.$X
(available in store actions/mutations too)App Config
Introducing
this.$config
, configurable:app.config
innuxt.config.js
config/app.js
orconfig/app/config.js
This config will be also available with
app.config
for plugins.Learn more on Nuxt Config improvements RFC
Nuxt plugins
This could also apply for plugins, but some plugins like nuxt-i18n to inject into
app
before instantiating it. See https://github.com/nuxt-community/nuxt-i18n/blob/master/src/plugins/main.js#L52Since we can generate this context before instantiating the app, something like this could do the trick for plugins:
Let me know your thinking and if I missed some use cases (I'm sure I missed some).