Skip to content

Commit 50f154a

Browse files
committed
chore:更新react服务端渲染使用文档
1 parent 5b2cfc2 commit 50f154a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

docs/服务端渲染/React-ssr.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ yarn start
9494
interface TviewOptions{
9595
ssr?: boolean, // 全局开启服务端渲染
9696
cache?: boolean, // 全局使用服务端渲染缓存
97-
useEngine?:boolean // 渲染自定义html的页面组件时,选择性开启使用模板引擎
97+
useEngine?: boolean, // 渲染自定义html的页面组件时,选择性开启使用模板引擎
98+
baseName?: string, //客户端根路由 仅使用react-router时有效
9899
}
99100
Result.reactView(viewName:string,initProps?:object,options?:TviewOptions);
100101
ctx.reactView(viewName:string,initProps?:object,options?:TviewOptions);
@@ -136,12 +137,12 @@ export default class Index extends BaseController {
136137
}
137138
```
138139

139-
## 11、**browserRouter**使用
140+
## 11、**客户端嵌套路由(react-router)**
140141

141142
> 在页面组件中使用 react-router 时,只能在 controller 中使用,切需要服务端对路由做支持。框架默认集成了 BrowserRouter,无需开发者在页面组件中引入
142143
143144
```js
144-
// 页面组件 web/browserRouter/index.js
145+
// 页面组件 web/home/index.js
145146
export default class APP extends Component {
146147
render() {
147148
return (
@@ -155,13 +156,15 @@ export default class APP extends Component {
155156
}
156157
}
157158

158-
// 服务端路由 前后端路由规则必须保持一致
159-
@Path("/browserRouter","/browserRouter/:path")
159+
// 服务端路由 前后端路由规则必须保持一致
160+
@Path("/home","/home/:path")
160161
browserRouter() {
161-
return Result.reactView('browserRouter',{say:"hi,I am a ReactView"},{cache:true});
162+
return Result.reactView('home',{say:"hi,I am a ReactView"},{cache:true,baseName:'home'});
162163
}
163164
```
164165

166+
**注:`baseName`默认为页面组件标识名称。和pages下的页面文件名称保持一致,当服务端根路由和文件名称不一致时,需要给插件传递`baseName`属性,以确保服务端和客户端根路由一致。**
167+
165168
## 12、**SEO 和自定义 HTML**
166169

167170
> 在 SEO 场景时,需要动态修改页面的标题和关键字等信息时,我们可以在自定义 html 中使用模板引擎语法,使用模板引擎时需要先开启使用`@umajs/plugin-views`插件并设置`useEngine:true`;建议和`nunjucks`搭配使用。[参考 demo](https://github.com/Umajs/umajs-react-ssr/tree/master/web/pages/template)

0 commit comments

Comments
 (0)