vue history模式配置
vue history模式配置(打包后)
·
vue 的路由模式分为history模式和hash模式两种。hash模式会在地址栏中添加#字符串,用于分隔前端路由。 在地址栏里面输入hash模式的地址时,会进行分割。 先判断能不能在router.js文件中找到对应的配置,如果能找则是路由地址,否则会想服务器发送请求。但是history模式不包含标志位,所以都会直接向服务器发送请求。所以我们需要做配置。 这里以nginx为例。
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
# 添加这行配置
try_files $uri $uri/ @router;#cl
}
# 添加这段配置
location @router {
rewrite ^.*$ /index.html last;
}
...}
更多推荐
已为社区贡献1条内容
所有评论(0)