BO

vue 配置去掉#号、非根目录设置
去掉想将vue url中的#去掉,需要把vue从 vue-router 默认的 hash 模式 ,改为histor...
扫描右侧二维码阅读全文
31
2019/12

vue 配置去掉#号、非根目录设置

去掉

想将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;
}
Last modification:December 31st, 2019 at 05:32 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment