umi icon indicating copy to clipboard operation
umi copied to clipboard

[Bug] ssr 未处理 base

Open PeachScript opened this issue 2 years ago • 4 comments

What happens?

开启 ssr 后输出产物中的前端路由链接 href 没有正确的 base 前缀

How To Reproduce

Steps to reproduce the behavior:

  1. Umi 脚手架开启 ssr + exportStatic 配置项
  2. 配置 basepublicPath 均为 /a/
  3. 配置 outputPathdist/a
  4. 执行构建
  5. 托管 dist 目录并通过浏览器访问 /a 路径下的应用
  6. 检查源代码中前端路由连接的 href 值会发现不是 /a/ 前缀

Expected behavior

前端路由连接的 href 值为 /a/ 前缀

关键代码位置:https://github.com/umijs/umi/blob/master/packages/renderer-react/src/server.tsx#L17

Context

  • Umi Version: 4.x
  • Node Version: 16.x
  • Platform: macOS

PeachScript avatar Jun 05 '23 03:06 PeachScript

6. 检查源代码中前端路由连接的 href 值会发现不是 /a/ 前缀

确实不是 /a/ 前缀, 但是启动 dist server 后点击 href 还是正常跳转了的, 这是一个 bug 吗?

Wxh16144 avatar Jul 26 '23 10:07 Wxh16144

是 bug,点击能正确跳转应该是因为 react-router 劫持了超链接默认行为,但对于搜索引擎(SEO)或浏览器(新窗口打开)来说,链接就是错误的了

PeachScript avatar Jul 27 '23 07:07 PeachScript

好, 交给我试试

Wxh16144 avatar Jul 27 '23 08:07 Wxh16144

我现在用的3.5也遇到了这个问题,添加base后,ssr渲染 无法成功,并且控制台总是报did not match错误

xlei1123 avatar Aug 06 '23 12:08 xlei1123