Some problems encountered in the implementation of vue-cli packaging one code and sharing multiple projects

question

now the requirement is to package a piece of code, but for multiple projects, it is packaged and put directly locally, and tested with tomcat services. For example,

means that relative path packaging needs to be carried out in history mode. At present, my practice is to obtain the base, of pathname dynamic change router, such as a project to change base to"/ segment/fault/a/main",. At present, it is possible for me to pack the package once, and the four projects share a code, but the address is different. This method is not robust. if the gods have other ways to package once and share a code with multiple addresses, they would like to share .

the current problem is:

I can access http://localhost:39090/segment/fault/a/main/ directly in the address bar (redirected in the route), and route switching is not a problem, but I cannot access it by typing http://localhost:39090/segment/fault/a/main/TestManagement or other specified routes in the address bar. I really don"t understand why. If you start the service locally npm run dev , there is no problem with either of the two access methods.

router settings

  http://localhost:39090/segment/fault/c/main/

can be accessed under these directories, and the corresponding route http://localhost:39090/segment/fault/a/main/TestManagement

can be accessed directly.

Thank you very much!


each corresponds to a template index.html . Just set < base href= "" > in the file


vue-cli 3, there is a setting for baseUrl. After setting it, the setting base for initialization of vue-router is as follows:

new webpack.DefinePlugin({
  'process.env': {
    BASE_URL: JSON.stringify('')
  }
})

then make the same settings in vue-router.

Menu