0

I'm building a Nuxt.js (vue.js) app. Since nuxt automatically generate routes based on directory structure within pages folder. I was wondering how it would handle subdomains.

I want to create a folder named pages/subdomains and want to redirect all subdomains to this folder. How can I achieve this via Nuxt?

2 Answers 2

1

this might not have existed when you first asked, but it looks like there's a module 'k-domains' that can solve this.

https://morioh.com/p/4b2454c8897c

Easy to use, for example:

  export default {
    buildModules: [
      [ "k-domains", {
          subDomains: ["blog", "projects", "anotherSubDomain" ], // List of directories to hold te pages for your subdomains
          rootDomain: "main-domain" //  directory to hold the pages for root domain  
      }
      ],
      ["@nuxtjs/router",{
          keepDefaultRouter: true // this line is mandatory...
      }
      ]
    ]
}

with a file tree like:

|   
|─pages
|   ├───blog
|   ├───projects
|   ├───main-domain
|   └───anotherSubDomain
Sign up to request clarification or add additional context in comments.

Comments

-2

Is this what you want? https://nuxtjs.org/api/configuration-router/#base

Add this code in your nuxt.config.js

export default {
  router: {
    base: '/pages/subdomains/'
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.