Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

启用SSR后,basename配置无效 #611

Open
zhangwenan opened this issue Feb 20, 2021 · 2 comments
Open

启用SSR后,basename配置无效 #611

zhangwenan opened this issue Feb 20, 2021 · 2 comments

Comments

@zhangwenan
Copy link

npm init rax
选择 App (Build universal application)
选择 Web 单页应用
选择 JavaScript
修改app.js

runApp({
  router: {
    type: "browser",
    basename: "/testrouter"
  }
});

npm i
npm start

此时,访问 http://localhost:3333/testrouterhttp://localhost:3333/,
都可以正常访问。

build.json 文件中加入ssr配置如下。

"web": {
    "ssr": true
  },

此时,重新npm start,
访问http://localhost:3333/ 正常。
但是,访问 http://localhost:3333/testrouter, 提示Cannot find target page.

期望的结果是什么

期望结果:能够正常访问 http://localhost:3333/testrouter

相关环境信息

  • rax-app 版本:3.3.7
  • build.json 配置
{
  "targets": [
    "web"
  ],
  "web": {
    "ssr": true
  },
  "plugins": [
    "@ali/build-plugin-rax-app-def"
  ]
}
  • Node 版本:v13.12.0
  • 操作系统:mac 10.15.5
@SoloJiang
Copy link
Contributor

这个问题产生原因是,basename 是一个运行时配置,在 SSR 的时候去决定渲染哪个页面是根据 app.json 配置的 path 来确定的,所以实现上目前做不到将 ${basename}/${path} 去和 path 匹配找到对应需要渲染的组件,即 SSR 场景下无法支持配置 basename

@SoloJiang
Copy link
Contributor

理论上可以对请求路径做模糊匹配,只是会存在一定的不确定性,比如 app.json 中找不到 ${basename}/${path} => request.path.indexOf(path) > -1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants