#去掉

想将vue url中的#去掉,需要把vue从 vue-router 默认的 hash 模式 ,改为history 模式 ,同时后台要做相关的设置。
具体在router =>index.js 添加

const router = new Router({
  mode: "history",
  routes: [...]
......

nginx 添加

location / {
  try_files $uri $uri/ /index.html;
}

apache 添加

<IfModule mod_rewrite.c>
 RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /project-name/index.html [L]
</IfModule>

非根目录配置

1.config => index.js

....
    assetsRoot: path.resolve(__dirname, "../dist"),
    assetsSubDirectory: "static",
    assetsPublicPath: "/portal/",
....

把 assetsPublicPath: "/", 修改成 assetsPublicPath: "/portal/", portal是目录名

2.router => index.js

const router = new Router({
  mode: "history",
  base: "/portal/",
  routes: [...]
......

增加基础路径 base:"/portal/"

3.nginx

location / {
  try_files $uri $uri/ /portal/index.html;
}

Q.E.D.