Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I access nuxt context in nuxt.config.js?

I'm using nuxt-i18n and @nuxtjs/auth and I want to config the auth.redirect option to support i18n like this:

// nuxt.config.js

export default {
  modules: [
    '@nuxtjs/auth',
    'nuxt-i18n',
    // ...
  ],
  auth: {
    redirect: {
      home: localePath('/dashboard'),
      // ...
    },
  },
  // ...
};

Normally, just like this.$store, I can access that localePath function provided by nuxt-i18n through app instance or the context like this.$localePath or app.localePath. But how can use it inside the nuxt.config.js file?

like image 975
STEN Avatar asked Mar 31 '20 15:03

STEN


People also ask

What is Nuxt config js used for?

This option lets you configure various settings for the build step, including loaders , filenames , the webpack config and transpilation .

What is Nuxt context?

The Nuxt context is an additional collection of data about the current request to the application that is available in Nuxt Lifecycle Hooks. This object is available to some Nuxt functions like asyncData and nuxtServerInit .

What is Nuxt Runtime config?

Nuxt provides a runtime config API to expose configuration within your application and server routes, with the ability to update it at runtime by setting environment variables.

Does NUXT js use webpack?

Nuxt lets you customize the webpack configuration for building your web application as you want.


1 Answers

In case of @nuxt/auth module with i18n redirection support problem, I've found a workaround: https://github.com/nuxt-community/auth-module/issues/1116#issuecomment-824814739.

Credit @azrikahar

like image 57
STEN Avatar answered Oct 01 '22 15:10

STEN