tomcat服务如何配置vue-router的history模式

官网只有apache的,不太明白tomcat怎么弄

阅读 8.8k
2 个回答

tomcat下需要新建WEB-INF文件夹并在其下新建web.xml文件

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  version="3.0"
  metadata-complete="true">

  <display-name>webapp</display-name>
  <description>
     webapp
  </description>
  <error-page>  
   <error-code>404</error-code>  
   <location>/</location>  
</error-page>  
</web-app>

nginx部署起来最方便了。
···使用try_files

location /admin {

        access_log  /data/nginx/logs/admin--$date_udf.log  main;
        root   /data/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ @router;
    }
    location @router {
        rewrite ^.*$ /admin/index.html last;
    }

···使用if判断

    location /admin/ {
        access_log  /data/nginx/logs/hxxtwx.log  main;
        root   /data/nginx/html/;
        index  index.html index.htm;

        if (!-e $request_filename) {
            rewrite ^/(.*) /admin/index.html last;
            break;
        }
    }

···可能还有其他方式

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题