Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a multipage Vue.js application with pages on nested subdirectories by modifying vue.config.js?

I have a multipage Vue.js application with working pages on domain/legal; domain/submit; etc. I've implemented that with the help of Vue.js' pages (i.e. customizing vue.config.js)

In other words, I'm all good making the above work.

I'm now trying to implement further nested pages under a new subdirectory level (additionally to the ones I already have as per above). i.e.

  • domain/org/profile1
  • domain/org/profile2
  • domain/org/profile3

Any way to make this work by customizing vue.config.js?

Current attempt vue.config.js code:

module.exports = {
  pages: {
    index: {
      entry: "./src/pages/home/main.js",
      template: "public/index.html",
      title: "Home",
      chunks: ["chunk-vendors", "chunk-common", "index"],
    },
    legal: {
      entry: "./src/pages/legal/main.js",
      template: "public/index.html",
      title: "Legal",
      chunks: ["chunk-vendors", "chunk-common", "legal"],
    },
    submit: {
      entry: "./src/pages/submit/main.js",
      template: "public/index.html",
      title: "Submit",
      chunks: ["chunk-vendors", "chunk-common", "submit"],
    },
    org: {
      digitalocean: {
        entry: "./src/pages/org/digitalocean/main.js",
        template: "public/index.html",
        title: "Digital Ocean",
        chunks: ["chunk-vendors", "chunk-common", "digitalocean"],
      },
    },
  },
};

And file structure:

src
-assets
-components
-pages
--home
    App.vue
    main.js
--legal
    App.vue
    main.js
--submit
    App.vue
    main.js
--org
---digitalocean
     App.vue
     main.js

This gives me the error:

Invalid options in vue.config.js: child "pages" fails because [child "org" fails because ["org" must be a string, "org" must be an array, child "entry" fails because ["entry" is required]]]

Pointers will be extremely welcome on how to make the nested pages work by modifying vue.config.js!

like image 750
Pat Avatar asked Jul 16 '20 12:07

Pat


People also ask

Which Vue Command inspect and modify the config?

You can also use the vue config command to inspect or modify the global CLI config.

Is Vue JS single-page app?

Vue. js has become one of the leading frameworks for building single-page applications.


1 Answers

I’ve managed to solve this with only vue.config.js with the below. Note: powerful little thing vue.config.js is:

├── src
│   ├── assets
│   │   └── logo.png
│   ├── components
│   │   └── HelloWorld.vue
│   └── pages
│       ├── home
│       │   ├── App.vue
│       │   ├── cache.js
│       │   └── main.js
│       ├── legal
│       │   ├── App.vue
│       │   └── main.js
│       ├── org
│       │   ├── digitalocean
│       │   │   ├── App.vue
│       │   │   └── main.js
│       │   └── intercom
│       └── submit
│           ├── App.vue
│           └── main.js
└── vue.config.js

And vue.config.js:

module.exports = {
  pages: {
    index: {
      entry: "./src/pages/home/main.js",
      template: "public/index.html",
      filename: "index.html",
      title: "Home",
      chunks: ["chunk-vendors", "chunk-common", "index"],
    },
    legal: {
      entry: "./src/pages/legal/main.js",
      template: "public/index.html",
      filename: "legal.html",
      title: "Legal",
      chunks: ["chunk-vendors", "chunk-common", "legal"],
    },
    submit: {
      entry: "./src/pages/submit/main.js",
      template: "public/index.html",
      filename: "submit.html",
      title: "Submit",
      chunks: ["chunk-vendors", "chunk-common", "submit"],
    },
    "org/digitalocean": {
      entry: "./src/pages/org/digitalocean/main.js",
      template: "public/index.html",
      filename: "org/digitalocean.html",
      title: "Digital Ocean",
      chunks: ["chunk-vendors", "chunk-common", "org/digitalocean"],
    },
  },
};
like image 174
Pat Avatar answered Oct 10 '22 05:10

Pat