Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

vue.js - vue-cli 3.0 multi page setup with HTML5 history mode

vue-cli 3.0 provides a pages config to configure multi page mode.

https://cli.vuejs.org/config/#pages

I'm currently trying to get the dev server working with HTML5 history mode, but with no luck so far.

Has anyone already tried this feature and got a working example?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to add configuration of devserver to vue.config.js.
By specifying rewrite for historyApiFallback, that problem is solved.

e.g. Implement multiple pages as index page and signin page

vue.config.js:

module.exports = {
  pages: {
    index: {
      entry: 'src/entry-point/index/main.js', //entry for the public page
      template: 'public/index.html', // source template
      filename: 'index.html' // output as dist/*
    },
    signin: {
      entry: 'src/entry-point/signin/main.js',
      template: 'public/signin.html',
      filename: 'signin.html'
    }
  },
  devServer: {
    historyApiFallback: {
      rewrites: [
        { from: //index/, to: '/index.html' },
        { from: //signin/, to: '/signin.html' }
      ]
    }
  }
}

In order to apply the above setting you need to run vue inspect, please be careful.


Also, be careful when baseUrl is specified. The following is stated in the document.

Some values like publicPath and historyApiFallback should not be modified as they need to be synchronized with baseUrl for the dev server to function properly.


So, in such a case, set a base tag to the template.

<base href="/appname/">


Since this is the configuration of the environment for development, please specify the redirect in the setting of hosting in the production environment.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...