emosheeep / vite-plugin-virtual-mpa

Out-of-box MPA plugin for Vite, generate multiple entries using only one template.
https://stackblitz.com/~/github.com/emosheeep/vite-plugin-virtual-mpa
MIT License
113 stars 15 forks source link

qiankun 项目里request header 中 accept 值为 “*/*”时报404 #49

Closed chaixingzhi closed 7 months ago

chaixingzhi commented 1 year ago

希望插件”htmlAcceptHeaders“可以支持非“text/html"类型的请求

emosheeep commented 1 year ago

可以整个最小复现demo吗,便于排查

chaixingzhi commented 1 year ago

https://gitee.com/chaixingzhi/vite-plugin-virtual-mpa-demo.git 这可能不算一个问题,但是我想知道这个有什么好的解决方案

emosheeep commented 1 year ago

看起来还真是,当 accept 从 */* 变成 text/html后请求就能正常发出了,因为History路由的重定向依赖这个判断是否为html入口,但是微前端框架里,页面都是用xhr请求的,我得想想🤔,你有好的建议也可以提出来

emosheeep commented 1 year ago

我之前用 garfish 做微前端的时候就没有遇到过这个问题,我在想会不会是框架实现细节上的偏差

emosheeep commented 1 year ago

我又研究了一下,感觉这里应该是通过代理的方式为相关请求加上 html 头来解决,因为插件如果无法判断当前请求是 html 请求,就不在插件的处理范围内了,那么 Fallback 行为就是不处理传递给 vite 处理,vite发现没有规则能处理,就会404。

看了下之前开发的 garfish 的时候,也是代理将子应用的入口文件直接打到服务器对应的 html 文件,省去了插件的处理,下面是 whistle 的代理配置:

image
  1. 一方面通过代理直接将对应路径打到 html 文件
  2. 另一方面补加了 text/html 头,双重保险,防止服务器 html fallback 行为出错

如果不想通过代理,也可以在子页面的插件配置里添加 rewrites 配置进行重定向,例如

image
chaixingzhi commented 1 year ago

感谢大佬

chaixingzhi commented 1 year ago

现在我也是用w2做了个转发,但是感觉在vite server上配置更优雅

chaixingzhi commented 1 year ago

奇怪的是,vue-cli-service 服务器好像没这个问题

emosheeep commented 1 year ago

奇怪的是,vue-cli-service 服务器好像没这个问题

你试试用vite起一个子应用呢,不用插件