nginx配置vue单页面应用

例如访问 https://xxxx:12306/overview

Nginx 配置

    location /overview/ {
      alias /home/data/overview/;
      try_files $uri $uri/ /overview/index.html;
      index index.html index.htm;
    }

前端路由配置

const routes = [
  {
    path: '/overview/login',
    name: 'login',
    component: () => import('@/views/Login/index.vue')
  },
  {
    path: '/overview',
    redirect: '/overview/home.vue'
  },
]

const router = createRouter({
  routes,
  history: createWebHistory()
})

export default router

vite配置

export default defineConfig({
  base: '/overview',
  // ...
})

你可能感兴趣的:(vue.js,nginx,前端)