vue3+vue-router4 路由HTML5模式(createWebHistory ),编译后部署到nginx,点击路由跳转正常,但是刷新页面报404

javascript 复制代码
import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/home',
    },
    {
      path: '/index/home',
      component: () => import('../views/index/Home.vue'),
    },
    {
      path: '/home',
      component: () => import('../views/home/Index.vue'),
    },
    {
      path: '/me',
      component: () => import('../views/me/Index.vue'),
    },
  ],
})

router.beforeEach((to, from) => {
  return true
})

export default router

不兼容:

bash 复制代码
    server {
        listen 80;
        server_name localhost chat.test.com;

        #配置根目录
        location / {
            root    /temp/test;
            index  index.html index.htm;
            add_header Content-Security-Policy upgrade-insecure-requests;
        }
    }  

解决方案:

bash 复制代码
    server {
        listen 80;
        server_name localhost chat.test.com;

        #配置根目录
        location / {
            root    /temp/test;
            #index  index.html index.htm;
            try_files $uri $uri/ /index.html;
            add_header Content-Security-Policy upgrade-insecure-requests;
        }
    }  

参考链接

https://router.vuejs.org/zh/guide/essentials/history-mode.html#nginx

人工智能学习网站

https://chat.xutongbao.top

相关推荐
小迷糊的学习记录2 小时前
Vuex 与 pinia
前端·javascript·vue.js
利刃大大2 小时前
【Vue】Element-Plus快速入门 && Form && Card && Table && Tree && Dialog && Menu
前端·javascript·vue.js·element-plus
小毛驴8504 小时前
Vue 路由示例
前端·javascript·vue.js
TT哇6 小时前
【实习 】银行经理端两个核心功能的开发与修复(银行经理绑定逻辑修复和线下领取扫码功能开发)
java·vue.js
星光不问赶路人7 小时前
vue3使用jsx语法详解
前端·vue.js
larance8 小时前
Gunicorn + Nginx+systemd 配置flask
nginx·flask·gunicorn
weixin79893765432...8 小时前
Vue 组件的更新过程(编译系统 + 响应式系统 + 虚拟 DOM & Diff)
vue.js
我是伪码农9 小时前
Vue 智慧商城项目
前端·javascript·vue.js
文艺理科生Owen9 小时前
Nginx 路径映射深度解析:从本地开发到生产交付的底层哲学
运维·nginx
小书包酱10 小时前
在 VS Code中,vue2-vuex 使用终于有体验感增强的插件了。
vue.js·vuex