vue-router history 使用

1. 修改router/index.js 

  mode: "history"

  base: "page"   // 打包后放到服务器上,  域名后面的目录 127.0.0.1/page/index.html

2. 修改vue.config.js 

  publicPath: '/page/'

3. 基于Apache服务配置文件修改

 /conf/httpd.conf   开启rewrite_module

  a. 找到 LoadModule rewrite_module libexec/apache2/ mod_rewrite.so  去掉#, 打开注释

    一般搜索 mod_rewrite.so ,  红色部分有的版本有,有的没有

  b. 找到 AllowOverride None    修改为   AllowOverride All    来使.htaccess 文件生效

4. 在127.0.0.1/page/  目录下添加.htaccess文件

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

最后一行  ./page/  域名后面的目录

原文地址:https://www.cnblogs.com/shenjilin/p/14696363.html