vue-router 默認 hash 模式,但是這種模式路由中帶有#號,比較丑,這時我們可以使用history模式來去掉#,具體步驟如下:
1、找到src/router/index.js,在創建router時增加base參數(假設設為你想要的根目錄web,訪問路由為:localhost:8080/web,localhost:8080/mobile)、mode參數(設置路由模式)
2、打開config/index.js,修改下列參數,本人根目錄設為web,所以下面紅框內的內容都改為web了
3、運行打包命令,得到名字為web的項目,拷到tomcat的webapps目錄下,並且新建WEB-INFO文件夾,里面包含web.xml文件(主要防止刷新頁面時出現404情況),web.xml文件內容如下:
其中display-name改為自己的根目錄,本人根目錄設為web,所以改為web
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1" metadata-complete="true"> <display-name>web</display-name> <error-page> <error-code>404</error-code> <location>/index.html</location> </error-page> </web-app>
-------------------------------------------------------------------------------------------------
QQ群:871934478
版權所有,轉載請注明源地址
-------------------------------------------------------------------------------------------------