zhangyuang / ssr

A most advanced ssr framework support React17/React18/Vue2/Vue3 on Earth that implemented serverless-side render specification.
http://doc.ssr-fc.com/
MIT License
2.59k stars 283 forks source link

使用不同的layout,具体使用样式无法支持 #146

Closed sendking closed 2 years ago

sendking commented 2 years ago

相关代码: https://github.com/sendking/ssr-antd-demo/commit/28dccb4ef65181e645db1a5870bdae27e8f981e1

需求:根据路由去使用不同的layout

问题:在layouts文件夹中根据路由判断不同的模版,具体模版样式无法使用,提示如图错误 image

Warning: Prop `style` did not match. Server: "null" Client: "font-size:22px;color:red"

zhangyuang commented 2 years ago
// 去掉 __isBrowser__ 判断,会导致 dom 结构不一致
// 有相关需求用 useEffect 做二次渲染
if (path?.includes('web')) {
    return <BasicLayout>
      {props.children!}
    </BasicLayout>
  } else {
    return <div style={{ backgroundColor: 'red' }}>
      {props.children!}
    </div>
  }
sendking commented 2 years ago

这个用法是解决了如上图的问题。

但是还有个问题:

  1. 访问 "/",刷次多次提示
  2. image

zhangyuang commented 2 years ago

仔细读文档faq