【vue】多个vue单页应用history模式如何配合 nginx 使用

多个vue单页应用使用history模式如何配合 nginx 使用

多个vue单页应用使用history模式如何改造;
该项目使用了微应用,地址:微应用 doc

前端项目结构:

frontend6(主项目)
|-- project(子项目)
|-- project2(子项目)

父项目针对子项目路由配置:

const routes = [
  {
    name: 'project',
    path: '/project',
    component: () => import('@/views/project/index'),
    meta: {
      model: 'project',
      info: { show_slider: true, is_inner: false },
    },
    children: [
      {
        name: 'micro',
        path: '*',
        component: () => import('@/views/project/index'),
        meta: {
          model: 'project_micro',
          info: { show_slider: true, is_inner: false },
        },
      },
    ],
  },
  {
    name: 'project2',
    path: '/project2',
    component: () => import('@/views/project2/index'),
    meta: {
      model: 'project2',
      info: { show_slider: true, is_inner: false },
    },
    children: [
      {
        name: 'micro',
        path: '*',
        component: () => import('@/views/project2/index'),
        meta: {
          model: 'project2_micro',
          info: { show_slider: true, is_inner: false },
        },
      },
    ],
  },
].concat(Home);

Nginx配置

nginx 只需要配置对 / 的代理就可以了:

server {
        listen       8099;
        server_name  localhost;
        
        location / {
            root  /Users/mac/Desktop/frontend6;
            add_header Cache-Control no-store;
			add_header Pragma no-cache;
			add_header Expires 0;
			# 下面配置让所有的资源走根目录
			proxy_set_header Host $host;
			try_files $uri $uri/ @router;
			index index.html index.htm;
        }
        
        # 不要漏掉这个
		location @router {
		    rewrite ^.*$ /index.html last;
		}
}

以上的配置完全可以完成history模式的配置,并且解决了浏览器中刷新页面出现 404 的问题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜七天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值