multiple pages in Vue.js CLI

First: always read the official documentation. With Vue you can build a SPA, and a MPA is also no problem. Just follow the guides:

You should create a new project with Vue CLI 3. Once you’ve created your project set it to be manually configured. Make sure you don’t choose the SPA option. Vue will then create a nice “start” project using a MPA approach. After that, just repeat the config on vue.config.js.


Updated #1

It seems that some updates on Vue Cli, have changed the way to build a MPA app, so:

  • Create a new application vue create test
  • Choose Manual configuration

The boilerplate created will be for a SPA. So make the following changes:

  • Create a folder under src named pages (optional)

  • Into this folder create your own pages: Home, About, etc.

  • Copy and paste the App.vue and main.js from src, into your new folders – Home, etc.

  • Format the App.vue into this folders, to your liking.

  • Create a vue.config.js and set it like this: https://cli.vuejs.org/config/#pages

Below, I have three images demonstrating this:

  • First: a fresh new app
  • Second: this same app, with the changes I made above
  • Third: the vue.config.js from this app

fresh new app
this same app, with the changes I made above
the vue.config.js from this app

You don’t need to create the pages folder, this is just to get the idea.

Link to GitHub: Building a MPA App

Leave a Comment