ice/website/docs/guide/basic/app.md

85 lines
1.6 KiB
Markdown
Raw Normal View History

文档 (#203) * feat: docs directory * docs: 调整结构 * chore: lock * feat: update docs * docs: update assets doc * 新增文档 for 介绍 and 环境变量 (#307) * docs: add about * docs: add docs for env * docs: update about * docs: config (#306) * docs: router (#304) * docs: router * feat: getconfig * docs: get data * docs: ssg * docs: ssr * docs: document * docs: page * docs: enable ssr * fix: title * Doc/rax compat (#303) * docs: add docs of rax-compat * docs: modify doc of rax compat * Docs: app entry (#301) * docs: app entry * docs: app entry * docs: mock (#245) * docs: mock * chore: typo * chore: title * docs: styles (#244) * docs: style * chore: acss title * Docs: contributing (#243) * docs: contributing * chore: typo * chore: update contributing docs * fix: typo * chore: add putteteer install * docs: quick start (#235) * docs: quick start * chore: update IDE * chore: update docs * docs: app directory (#236) * docs: directory * chore: document desc * docs: update website * docs: update about * docs: update docs * chore: update prism * chore: update docs * chore: update Co-authored-by: luhc228 <luhengchang228@126.com> Co-authored-by: ClarkXia <xiawenwu41@gmail.com> Co-authored-by: 逆葵 <xianyong.yxy@alibaba-inc.com> Co-authored-by: ZeroLing <zhuoling.lcl@alibaba-inc.com> Co-authored-by: ZeroLing <i@zeroling.com> Co-authored-by: 水澜 <shuilan.cj@taobao.com> Co-authored-by: 染陌同学 <answershuto@gmail.com> Co-authored-by: luhc228 <44047106+luhc228@users.noreply.github.com>
2022-07-01 16:47:25 +08:00
---
title: 应用入口
order: 4
---
ICE 通过应用配置的方式渲染整个应用,开发者可以根据提供的配置定制应用。
## 应用配置文件
框架以 `src/app.ts` 作为应用配置文件:
```tsx
import { defineAppConfig } from 'ice';
export default defineAppConfig({
app: {
strict: true,
},
});
```
> 推荐通过 `defineAppConfig()` 的方式导出应用配置,以获得良好的类型提示。
## 配置项
应用入口的配置项,支持应用常用的相关配置。
### app
#### `rootId`
根节点 id
- 类型:`string`
- 默认值 `ice-container`
#### `strict`
是否开启 React 的严格模式 (React.StrictMode)
- 类型 `boolean`
- 默认值 `false`
#### `errorBoundary`
是否启用内置的错误边界捕获能力
- 类型 `boolean`
- 默认值 `false`
### router
#### `type`
路由类型
- 类型 `string`,可选值为 `hash``browser`
- 默认为 `browser`
#### `basename`
路由 basename
- 类型 `string`
- 默认值 `/`
## 运行时拓展
应用入口除了支持定义应用配置之外,同时也承担运行时扩展的能力,比如权限配置:
```js
import { defineAppConfig } from 'ice';
import { defineAuthConfig } from '@ice/plugin-auth/esm/types';
// 导出 auth 相关的能力,该能力由 @ice/plugin-auth 插件提供
export const auth = defineAuthConfig(() => {
return {
initialAuth: {
admin: true,
},
};
});
export default defineAppConfig({
app: {
strict: true,
},
});
```
[//]: # (更多运行时插件能力,请参考[官方插件]&#40;/plugin/list/auth&#41;。)