Vue-Router中base应用

根据官方文档的描述

The base URL of the app. For example, if the entire single page application is served under /app/, then base should use the value “/app/”

因为我们平常开发测试 运行时候 一般执行

npm run serve
...
 App running at:
  - Local:   http://localhost:8080
  - Network: http://192.168.5.75:8080

  Note that the development build is not optimized.
  To create a production build, run npm run build.

所以项目的根路径就是’/’

但是再部署的时候,我们可能部署在nginx下的某个文件目录下比如
/app/这个时候 base 就要改成`/app/

所以测试环境与部署路径可能会有差别
所以一般我们可以这样做 Node_ENV 用vue默认的设置

const router = new VueRouter({
  mode: "history",
  base: process.env.NODE_ENV === "production" ? "/app/" : "/",
  routes
});

你可能感兴趣的:(vue.js,vue-router)