网站首页 > 技术文章 正文
在Umi3官方文档中,有一个配置项exportStatic需在配置文件(umirc.ts或config/config.ts)中设置,语法如下:
exportStatic
Type: object
此配置项有三个参数,规范如下:
1. htmlSuffix:启用.html 后缀。
2. dynamicRoot:部署到任意路径。
3. extraRoutePaths:生成额外的路径页面,用法和场景见预渲染动态路由
Umi框架配置 html 的输出形式,默认只输出 index.html。如果需要预渲染,请开启 ssr 配置,常用来解决没有服务端情况下,页面的 SEO 和首屏渲染提速。如果开启 exportStatic,则会针对每个路由输出 html 文件。
举个例子,路由配置如下:
/
/users
/list
在不开启 exportStatic 时,输出:
- index.html
设置 exportStatic: {} 后,输出:
- index.html
- users/index.html
- list/index.html
设置 exportStatic: { htmlSuffix: true } 后,输出:
- index.html
- users.html
- list.html
若有 SEO的话需求,可开启 ssr 配置,在 umi build 后,会路由(除静态路由外)渲染成有具体内容的静态 html 页面,例如在配置文件(umirc.ts | config/config.ts)中有如下路由配置:
{
routes: [
{
path: '/',
component: '@/layouts/Layout',
routes: [
{ path: '/', component: '@/pages/Index' },
{ path: '/bar', component: '@/pages/Bar' },
{ path: '/news', component: '@/pages/News' },
{ path: '/news/:id', component: '@/pages/NewsDetail' },
],
},
];
}
设置 { ssr: {}, exportStatic: { } 后,且在编译后,生成如下产物:
- dist
- umi.js
- umi.css
- index.html
- bar
- index.html
- news
- index.html
- [id].html
考虑到预渲染后,大部分不会再用到 umi.server.js 服务端文件,构建完成后会删掉 umi.server.js 文件如果有调试、不删除 server 文件需求,可通过环境变量 RM_SERVER_FILE=none 来保留。
转载:码书网「链接」
猜你喜欢
- 2024-10-21 HTML制作网页先熟悉CSS(用html和css做网页教程)
- 2024-10-21 HTML简单介绍及常见元素(html的元素组成部分有哪些?)
- 2024-10-21 Go Web 框架 Gin 学习2 - 模板渲染的2种方式
- 2024-10-21 HTML自定义组件(html 组件)
- 2024-10-21 Html小知识总结(html基础总结)
- 2024-10-21 你的HTML页面书写规范吗?必须知道的HTML书写规范
- 2024-10-21 用C++写出HTML,使用web服务,可以免费搭建个人博客
- 2024-10-21 【JavaScript】将执行上下文、作用域、闭包串联起来
- 2024-10-21 7.HTML中的列表、引用和代码的使用
- 2024-10-21 小白必看!Django 模板语言基础来啦
- 最近发表
- 标签列表
-
- cmd/c (57)
- c++中::是什么意思 (57)
- sqlset (59)
- ps可以打开pdf格式吗 (58)
- phprequire_once (61)
- localstorage.removeitem (74)
- routermode (59)
- vector线程安全吗 (70)
- & (66)
- java (73)
- org.redisson (64)
- log.warn (60)
- cannotinstantiatethetype (62)
- js数组插入 (83)
- resttemplateokhttp (59)
- gormwherein (64)
- linux删除一个文件夹 (65)
- mac安装java (72)
- reader.onload (61)
- outofmemoryerror是什么意思 (64)
- flask文件上传 (63)
- eacces (67)
- 查看mysql是否启动 (70)
- java是值传递还是引用传递 (58)
- 无效的列索引 (74)