ionic-expert
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseIonic Expert
Ionic 专家
Comprehensive reference for Ionic Framework development — core concepts, components, theming, lifecycle, navigation, framework-specific patterns (Angular, React, Vue), upgrading, and Capawesome Cloud integration.
Ionic Framework开发的全面参考指南,涵盖核心概念、组件、主题定制、生命周期、导航、框架专属模式(Angular、React、Vue)、版本升级以及Capawesome Cloud集成。
Core Concepts
核心概念
Ionic Framework is a UI toolkit for building cross-platform apps with web technologies. It provides 80+ pre-built UI components as Web Components prefixed with (e.g., , ).
ion-<ion-button><ion-content>- Platform modes: Components adapt styling to the platform. iOS devices use mode; Android and all other platforms use
ios(Material Design). Themdelement receives a class (<html>orios).md - Capacitor integration: Ionic handles the UI; Capacitor handles native device APIs. See the skill for Capacitor guidance.
capacitor-app-development - Framework support: Ionic integrates with Angular (), React (
@ionic/angular), and Vue (@ionic/react).@ionic/vue
Ionic Framework是使用Web技术构建跨平台应用的UI工具集,提供80+开箱即用的UI组件,均为带前缀的Web Components(例如、)。
ion-<ion-button><ion-content>- 平台模式:组件会根据运行平台自动适配样式。iOS设备使用模式;Android及其他所有平台使用
ios(Material Design)模式,md元素会自动添加对应的类(<html>或ios)。md - Capacitor集成:Ionic负责UI层,Capacitor负责原生设备API调用。Capacitor相关使用指南可参考技能文档。
capacitor-app-development - 框架支持:Ionic可与Angular()、React(
@ionic/angular)、Vue(@ionic/react)集成。@ionic/vue
Creating a New App
创建新应用
bash
npm install -g @ionic/cli
ionic start <name> <template> --type=<framework> --capacitor --package-id=<id> | Framework |
|---|---|
| Angular (NgModules) |
| Angular (Standalone Components) |
| React |
| Vue |
| Template | Description |
|---|---|
| Empty project, single page |
| Tab-based layout |
| Side menu layout |
For details, see ionic-app-creation.
bash
npm install -g @ionic/cli
ionic start <name> <template> --type=<framework> --capacitor --package-id=<id> | 对应框架 |
|---|---|
| Angular(NgModules模式) |
| Angular(独立组件模式) |
| React |
| Vue |
| 模板名 | 说明 |
|---|---|
| 空项目,仅包含单个页面 |
| 基于标签栏的布局 |
| 侧边菜单布局 |
详情请参考ionic-app-creation。
Ionic CLI
Ionic CLI
Run for the full and always up-to-date command list.
ionic --help| Command | Description |
|---|---|
| Scaffold a new Ionic project. |
| Start a local dev server with live reload (port 8100). |
| Build the web app for production. |
| Generate pages, components, services (framework-dependent). |
| Print system/environment info. |
| Remove and recreate dependencies and platform files. |
Useful flags: (all network interfaces), , , .
ionic serve--external--port=<port>--prod--no-open运行可查看完整的、最新的命令列表。
ionic --help| 命令 | 说明 |
|---|---|
| 脚手架生成新的Ionic项目 |
| 启动带热重载的本地开发服务器(默认端口8100) |
| 构建生产环境的Web应用 |
| 生成页面、组件、服务(依赖所使用的框架) |
| 打印系统/环境信息 |
| 移除并重建依赖和平台相关文件 |
常用的参数:(监听所有网络接口)、(指定端口)、、(启动后不自动打开浏览器)。
ionic serve--external--port=<port>--prod--no-openComponents Overview
组件概览
Ionic provides 80+ UI components organized by category. For full API reference (properties, events, methods, slots, CSS custom properties), see the linked reference files.
Ionic提供80+按类别整理的UI组件,完整的API参考(属性、事件、方法、插槽、CSS自定义属性)可查看对应的参考文档。
Layout
布局类
ion-appion-contention-headerion-footerion-toolbarion-titleion-buttonsion-back-buttonion-gridion-rowion-colion-split-paneKey usage:
html
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button defaultHref="/home"></ion-back-button>
</ion-buttons>
<ion-title>Page Title</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<!-- Scrollable content -->
</ion-content>For details, see components-layout.md.
ion-appion-contention-headerion-footerion-toolbarion-titleion-buttonsion-back-buttonion-gridion-rowion-colion-split-pane核心用法:
html
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button defaultHref="/home"></ion-back-button>
</ion-buttons>
<ion-title>页面标题</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<!-- 可滚动内容 -->
</ion-content>详情请参考components-layout.md。
Navigation
导航类
ion-tabsion-tab-barion-tab-buttonion-menuion-menu-buttonion-menu-toggleion-router-outletion-navion-breadcrumbsFor details, see components-navigation.md.
ion-tabsion-tab-barion-tab-buttonion-menuion-menu-buttonion-menu-toggleion-router-outletion-navion-breadcrumbs详情请参考components-navigation.md。
Form
表单类
ion-inpution-textareaion-selection-select-optionion-checkboxion-toggleion-radioion-radio-groupion-rangeion-datetimeion-datetime-buttonion-searchbarion-segmention-segment-buttonion-input-otpKey properties shared by most form components: , (, , , ), (, ), , , , , .
labellabelPlacementfloatingstackedfixedstartfilloutlinesoliderrorTexthelperTextdisabledvalueplaceholderKey events:
- — fires on each keystroke (use for
ionInput/ion-input).ion-textarea - — fires when value is committed (use for
ionChange,ion-select,ion-toggle,ion-checkbox).ion-range
html
<ion-input label="Email" labelPlacement="floating" fill="outline"
type="email" placeholder="you@example.com"
errorText="Invalid email" helperText="Enter your email">
</ion-input>
<ion-select label="Country" labelPlacement="floating" fill="outline" interface="popover">
<ion-select-option value="us">United States</ion-select-option>
<ion-select-option value="de">Germany</ion-select-option>
</ion-select>For details, see components-form.md.
ion-inpution-textareaion-selection-select-optionion-checkboxion-toggleion-radioion-radio-groupion-rangeion-datetimeion-datetime-buttonion-searchbarion-segmention-segment-buttonion-input-otp大多数表单组件共享的核心属性:、(、、、)、(、)、、、、、。
labellabelPlacementfloatingstackedfixedstartfilloutlinesoliderrorTexthelperTextdisabledvalueplaceholder核心事件:
- — 每次按键时触发(适用于
ionInput/ion-input)ion-textarea - — 值确认修改时触发(适用于
ionChange、ion-select、ion-toggle、ion-checkbox)ion-range
html
<ion-input label="邮箱" labelPlacement="floating" fill="outline"
type="email" placeholder="you@example.com"
errorText="邮箱格式无效" helperText="请输入你的邮箱">
</ion-input>
<ion-select label="国家" labelPlacement="floating" fill="outline" interface="popover">
<ion-select-option value="us">美国</ion-select-option>
<ion-select-option value="de">德国</ion-select-option>
</ion-select>详情请参考components-form.md。
Overlays
浮层类
ion-modalion-alertion-toastion-action-sheetion-loadingion-popoverAll overlays share: prop for declarative control, prop to open from a button ID, , , and lifecycle events (, , , ).
isOpentriggerbackdropDismissanimateddidPresentdidDismisswillPresentwillDismissSheet modal (bottom sheet):
html
<ion-modal [isOpen]="isOpen" [breakpoints]="[0, 0.5, 1]" [initialBreakpoint]="0.5" [handle]="true">
<ion-content>Sheet content</ion-content>
</ion-modal>For details, see components-overlay.md.
ion-modalion-alertion-toastion-action-sheetion-loadingion-popover所有浮层共享的特性:属性用于声明式控制显隐、属性绑定按钮ID实现点击打开、、,以及生命周期事件(、、、)。
isOpentriggerbackdropDismissanimateddidPresentdidDismisswillPresentwillDismiss底部弹窗(Sheet modal):
html
<ion-modal [isOpen]="isOpen" [breakpoints]="[0, 0.5, 1]" [initialBreakpoint]="0.5" [handle]="true">
<ion-content>弹窗内容</ion-content>
</ion-modal>详情请参考components-overlay.md。
Data Display
数据展示类
ion-listion-itemion-item-slidingion-item-optionsion-item-optionion-cardion-card-headerion-card-contention-accordionion-accordion-groupion-chipion-badgeion-labelion-noteFor details, see components-data-display.md.
ion-listion-itemion-item-slidingion-item-optionsion-item-optionion-cardion-card-headerion-card-contention-accordionion-accordion-groupion-chipion-badgeion-labelion-noteScroll
滚动相关
ion-refresherion-refresher-contention-infinite-scrollion-infinite-scroll-contention-reorder-groupion-reorderFor details, see components-scroll.md.
ion-refresherion-refresher-contention-infinite-scrollion-infinite-scroll-contention-reorder-groupion-reorder详情请参考components-scroll.md。
Actions & Media
操作与媒体类
ion-buttonion-fabion-fab-buttonion-iconion-avatarion-thumbnailion-spinnerion-skeleton-textion-progress-barFor details, see components-action.md and components-media.md.
ion-buttonion-fabion-fab-buttonion-iconion-avatarion-thumbnailion-spinnerion-skeleton-textion-progress-barTheming
主题定制
Colors
颜色
Nine default colors: , , , , , , , , . Apply via the attribute:
primarysecondarytertiarysuccesswarningdangerlightmediumdarkcolorhtml
<ion-button color="primary">Save</ion-button>
<ion-button color="danger">Delete</ion-button>Customize a color by overriding all six CSS variables in :
:rootcss
:root {
--ion-color-primary: #3880ff;
--ion-color-primary-rgb: 56, 128, 255;
--ion-color-primary-contrast: #ffffff;
--ion-color-primary-contrast-rgb: 255, 255, 255;
--ion-color-primary-shade: #3171e0;
--ion-color-primary-tint: #4c8dff;
}默认提供9种颜色:、、、、、、、、,通过属性使用:
primarysecondarytertiarysuccesswarningdangerlightmediumdarkcolorhtml
<ion-button color="primary">保存</ion-button>
<ion-button color="danger">删除</ion-button>可通过在中覆盖对应的6个CSS变量来自定义颜色:
:rootcss
:root {
--ion-color-primary: #3880ff;
--ion-color-primary-rgb: 56, 128, 255;
--ion-color-primary-contrast: #ffffff;
--ion-color-primary-contrast-rgb: 255, 255, 255;
--ion-color-primary-shade: #3171e0;
--ion-color-primary-tint: #4c8dff;
}Global CSS Variables
全局CSS变量
Key variables: , , , , , .
--ion-background-color--ion-text-color--ion-font-family--ion-safe-area-top/right/bottom/left--ion-margin--ion-padding核心变量:、、、、、。
--ion-background-color--ion-text-color--ion-font-family--ion-safe-area-top/right/bottom/left--ion-margin--ion-paddingDark Mode
深色模式
Three approaches (import from , , or ):
@ionic/angular/css/@ionic/react/css/@ionic/vue/css/- System preference (default):
@import '@ionic/<framework>/css/palettes/dark.system.css'; - Always dark:
@import '@ionic/<framework>/css/palettes/dark.always.css'; - CSS class toggle: then add
@import '@ionic/<framework>/css/palettes/dark.class.css';to.ion-palette-dark.<html>
三种实现方式(从、或导入对应文件):
@ionic/angular/css/@ionic/react/css/@ionic/vue/css/- 跟随系统设置(默认):
@import '@ionic/<framework>/css/palettes/dark.system.css'; - 始终深色:
@import '@ionic/<framework>/css/palettes/dark.always.css'; - CSS类切换:,之后给
@import '@ionic/<framework>/css/palettes/dark.class.css';添加<html>类即可开启深色模式。.ion-palette-dark
Platform Styles
平台专属样式
Target platform-specific styles in CSS using the mode class on :
<html>css
.ios ion-toolbar { --background: #f8f8f8; }
.md ion-toolbar { --background: #ffffff; }Preview a specific mode in the browser:
http://localhost:8100/?ionic:mode=ios可通过上的模式类在CSS中针对不同平台写专属样式:
<html>css
.ios ion-toolbar { --background: #f8f8f8; }
.md ion-toolbar { --background: #ffffff; }在浏览器中预览指定模式:
http://localhost:8100/?ionic:mode=iosLayout
布局
Grid System
栅格系统
12-column flexbox grid: , , . Columns expand evenly unless (1-12) is specified.
ion-gridion-rowion-colsize| Breakpoint | Min Width | Property Suffix |
|---|---|---|
| 0 | |
| 576px | |
| 768px | |
| 992px | |
| 1200px | |
基于flexbox的12列栅格系统:、、。未指定(1-12)时列会均匀分配宽度。
ion-gridion-rowion-colsize| 断点 | 最小宽度 | 属性后缀 |
|---|---|---|
| 0 | |
| 576px | |
| 768px | |
| 992px | |
| 1200px | |
CSS Utility Classes
CSS工具类
- Padding: ,
.ion-padding,.ion-padding-top/bottom/start/end.ion-no-padding - Margin: ,
.ion-margin,.ion-margin-top/bottom/start/end.ion-no-margin - Text: ,
.ion-text-center,.ion-text-start,.ion-text-end,.ion-text-wrap.ion-text-nowrap - Display: ,
.ion-display-none,.ion-display-block.ion-display-flex - Flex: ,
.ion-justify-content-center,.ion-align-items-center,.ion-flex-row.ion-flex-column
All utility classes support responsive suffixes: (applies at 768px+).
.ion-text-md-center- 内边距:、
.ion-padding、.ion-padding-top/bottom/start/end.ion-no-padding - 外边距:、
.ion-margin、.ion-margin-top/bottom/start/end.ion-no-margin - 文本:、
.ion-text-center、.ion-text-start、.ion-text-end、.ion-text-wrap.ion-text-nowrap - 显示:、
.ion-display-none、.ion-display-block.ion-display-flex - Flex:、
.ion-justify-content-center、.ion-align-items-center、.ion-flex-row.ion-flex-column
所有工具类都支持响应式后缀:例如仅在768px以上宽度生效。
.ion-text-md-centerPage Lifecycle
页面生命周期
Ionic provides four lifecycle hooks that fire during page transitions. These exist because caches pages in the DOM — framework-native lifecycle hooks (, , ) only fire once on first creation, not on every page visit.
ion-router-outletngOnInituseEffectonMounted| Hook | Fires When | Use For |
|---|---|---|
| Page about to enter (pre-animation) | Refresh data on every visit |
| Page fully entered (post-animation) | Start animations, focus inputs |
| Page about to leave (pre-animation) | Save state, pause subscriptions |
| Page fully left (post-animation) | Clean up off-screen resources |
Critical rules:
- Only fire on components directly mapped to a route via .
ion-router-outlet - Child components do not receive these events.
- The component must use the framework-specific page wrapper (see framework sections below).
Ionic提供4个页面转场时触发的生命周期钩子。这些钩子存在的原因是会在DOM中缓存页面——框架原生的生命周期钩子(、、)仅在页面首次创建时触发一次,不会在每次进入页面时触发。
ion-router-outletngOnInituseEffectonMounted| 钩子 | 触发时机 | 适用场景 |
|---|---|---|
| 页面即将进入(动画开始前) | 每次进入页面时刷新数据 |
| 页面完全进入(动画结束后) | 启动动画、聚焦输入框 |
| 页面即将离开(动画开始前) | 保存状态、暂停订阅 |
| 页面完全离开(动画结束后) | 清理页外资源 |
重要规则:
- 仅直接通过映射到路由的组件才会触发这些钩子
ion-router-outlet - 子组件不会收到这些生命周期事件
- 组件必须使用对应框架的页面包装器(参考下文框架专属模式章节)
Framework-Specific Patterns
框架专属模式
Angular
Angular
For full details, see ionic-angular.
Detect architecture: Check for (standalone) vs (NgModule).
src/main.tsbootstrapApplicationplatformBrowserDynamic().bootstrapModule| Aspect | Standalone | NgModule |
|---|---|---|
| Ionic setup | | |
| Component imports | Each from | |
| Lazy loading | | |
| Icons | | Automatic |
Navigation: Use from for animated navigation (, , , ). Use with in templates.
NavController@ionic/angularnavigateForwardnavigateBacknavigateRootbackrouterLinkrouterDirectionLifecycle: Implement interfaces , , , from :
ViewWillEnterViewDidEnterViewWillLeaveViewDidLeave@ionic/angulartypescript
import { ViewWillEnter } from '@ionic/angular';
@Component({ /* ... */ })
export class HomePage implements ViewWillEnter {
ionViewWillEnter() {
this.loadData(); // Runs on every page visit
}
}For navigation details, see angular/navigation.md. For lifecycle details, see angular/lifecycle.md.
完整详情请参考ionic-angular。
判断架构模式:查看,如果有则是独立组件模式,如果是则是NgModule模式。
src/main.tsbootstrapApplicationplatformBrowserDynamic().bootstrapModule| 维度 | 独立组件模式 | NgModule模式 |
|---|---|---|
| Ionic初始化 | 在 | 在 |
| 组件导入 | 每个组件都从 | |
| 懒加载 | 路由中使用 | 路由中使用 |
| 图标 | 需要从 | 自动加载 |
导航:使用提供的实现带动画的导航(、、、),模板中可搭配使用。
@ionic/angularNavControllernavigateForwardnavigateBacknavigateRootbackrouterDirectionrouterLink生命周期:实现提供的、、、接口:
@ionic/angularViewWillEnterViewDidEnterViewWillLeaveViewDidLeavetypescript
import { ViewWillEnter } from '@ionic/angular';
@Component({ /* ... */ })
export class HomePage implements ViewWillEnter {
ionViewWillEnter() {
this.loadData(); // 每次进入页面都会执行
}
}导航详情请参考angular/navigation.md,生命周期详情请参考angular/lifecycle.md。
React
React
For full details, see ionic-react.
Key setup differences:
- Call before rendering in
setupIonicReact().src/main.tsx - Use (from
IonReactRouter) instead of@ionic/react-router.BrowserRouter - Use to contain routes with the
IonRouterOutletprop (notcomponentorrender).children - Every page must render as root — required for transitions and lifecycle hooks.
IonPage
Navigation: Use hook for programmatic navigation:
useIonRoutertypescript
import { useIonRouter } from '@ionic/react';
const router = useIonRouter();
router.push('/detail/123', 'forward', 'push');
router.goBack();Lifecycle hooks (from ):
@ionic/reacttypescript
import { useIonViewWillEnter } from '@ionic/react';
useIonViewWillEnter(() => {
fetchData(); // Runs on every page visit
});Overlay hooks: , , , , , , .
useIonAlertuseIonToastuseIonActionSheetuseIonLoadinguseIonModaluseIonPopoveruseIonPickerForm events: Use for /, for ///. Access values via .
onIonInputIonInputIonTextareaonIonChangeIonSelectIonToggleIonCheckboxIonRangee.detail.valueFor routing details, see react/routing.md. For hooks, see react/hooks.md.
完整详情请参考ionic-react。
核心初始化差异:
- 在中渲染应用前调用
src/main.tsxsetupIonicReact() - 使用提供的
@ionic/react-router代替原生的IonReactRouterBrowserRouter - 使用容纳路由,必须使用
IonRouterOutlet属性(不能用component或render)children - 每个页面的根组件必须是——这是转场动画和生命周期钩子生效的必要条件
IonPage
导航:使用钩子实现编程式导航:
useIonRoutertypescript
import { useIonRouter } from '@ionic/react';
const router = useIonRouter();
router.push('/detail/123', 'forward', 'push');
router.goBack();生命周期钩子(来自):
@ionic/reacttypescript
import { useIonViewWillEnter } from '@ionic/react';
useIonViewWillEnter(() => {
fetchData(); // 每次进入页面都会执行
});浮层钩子:、、、、、、。
useIonAlertuseIonToastuseIonActionSheetuseIonLoadinguseIonModaluseIonPopoveruseIonPicker表单事件:/使用,///使用,通过获取值。
IonInputIonTextareaonIonInputIonSelectIonToggleIonCheckboxIonRangeonIonChangee.detail.value路由详情请参考react/routing.md,钩子详情请参考react/hooks.md。
Vue
Vue
For full details, see ionic-vue.
Key setup differences:
- Install plugin in
IonicVue:src/main.ts.createApp(App).use(IonicVue).use(router) - Import from
createRouter(not from@ionic/vue-router).vue-router - Every page must use as root template element — without it, transitions and lifecycle hooks silently fail.
IonPage - Import all Ionic components from .
@ionic/vue - Use kebab-case for event names in templates (,
@ion-change).@ion-input - Import icons as SVG references from — never as strings.
ionicons/icons
Navigation: Use composable:
useIonRoutervue
<script setup lang="ts">
import { useIonRouter } from '@ionic/vue';
const ionRouter = useIonRouter();
ionRouter.push('/detail/123');
ionRouter.back();
</script>Declarative:
<ion-button router-link="/detail" router-direction="forward">Go</ion-button>Lifecycle hooks (from ):
@ionic/vuevue
<script setup lang="ts">
import { onIonViewWillEnter } from '@ionic/vue';
onIonViewWillEnter(() => {
fetchData(); // Runs on every page visit
});
</script>Composables: , , , , .
useIonRouter()useBackButton(priority, handler)useKeyboard()isPlatform(name)getPlatforms()Access Web Component methods via : .
$elcontentRef.value.$el.scrollToBottom(300)For navigation details, see vue/navigation.md. For composables, see vue/composables.md.
完整详情请参考ionic-vue。
核心初始化差异:
- 在中安装
src/main.ts插件:IonicVuecreateApp(App).use(IonicVue).use(router) - 从导入
@ionic/vue-router(不要从createRouter导入)vue-router - 每个页面的模板根元素必须是——缺少的话转场动画和生命周期钩子会静默失效
IonPage - 所有Ionic组件都从导入
@ionic/vue - 模板中事件名使用短横线命名(、
@ion-change)@ion-input - 图标从导入为SVG引用,不要用字符串形式
ionicons/icons
导航:使用组合式函数:
useIonRoutervue
<script setup lang="ts">
import { useIonRouter } from '@ionic/vue';
const ionRouter = useIonRouter();
ionRouter.push('/detail/123');
ionRouter.back();
</script>声明式导航:
<ion-button router-link="/detail" router-direction="forward">跳转</ion-button>生命周期钩子(来自):
@ionic/vuevue
<script setup lang="ts">
import { onIonViewWillEnter } from '@ionic/vue';
onIonViewWillEnter(() => {
fetchData(); // 每次进入页面都会执行
});
</script>组合式函数:、、、、。
useIonRouter()useBackButton(priority, handler)useKeyboard()isPlatform(name)getPlatforms()通过访问Web Component方法:。
$elcontentRef.value.$el.scrollToBottom(300)导航详情请参考vue/navigation.md,组合式函数详情请参考vue/composables.md。
Navigation Patterns
导航模式
Tab Navigation
标签栏导航
Each framework uses with and child routes per tab. Each tab maintains its own navigation stack.
ion-tabsion-tab-barRules:
- The attribute on
tabmust match the child route path.ion-tab-button - Never navigate between tabs programmatically — only the tab bar buttons should switch tabs.
- For shared views across tabs, use instead of cross-tab routing.
ion-modal
所有框架都使用搭配,每个标签对应子路由,每个标签维护独立的导航栈。
ion-tabsion-tab-bar规则:
- 的
ion-tab-button属性必须和子路由路径匹配tab - 不要通过编程方式在标签之间跳转,仅通过标签栏按钮切换标签
- 标签间共享的页面使用实现,不要跨标签路由
ion-modal
Side Menu
侧边菜单
Use with matching the on . Wrap menu items in to auto-close after selection. Use for top-level menu navigation.
ion-menucontentIdidion-router-outletion-menu-togglerouterDirection="root"使用,其要和的匹配。菜单项用包裹,实现点击后自动关闭菜单。顶层菜单导航使用。
ion-menucontentIdion-router-outletidion-menu-togglerouterDirection="root"Linear vs. Non-Linear Routing
线性 vs 非线性路由
- Linear: Sequential forward/back navigation (list -> detail -> edit). Back button returns to the previous page.
- Non-linear: Multiple independent stacks (tabs). Back navigation stays within the current tab's stack.
Use non-linear routing for tabs or split-pane layouts. Use linear routing for simple page flows.
- 线性:顺序前进/后退导航(列表 -> 详情 -> 编辑),返回按钮回到上一个页面
- 非线性:多个独立的导航栈(标签栏),返回操作仅在当前标签的栈内生效
标签栏或分栏布局使用非线性路由,简单页面流使用线性路由。
Upgrading
版本升级
Ionic supports upgrades from version 4 through 8. Each major version jump must be applied sequentially — do not skip intermediate versions.
For full upgrade guides, see ionic-app-upgrades.
Ionic支持从4版本升级到8版本,大版本升级必须依次执行,不要跳过中间版本。
完整的升级指南请参考ionic-app-upgrades。
Capacitor Integration
Capacitor集成
Ionic apps use Capacitor for native device features (camera, filesystem, push notifications, etc.). The standard workflow:
bash
npm run build
npx cap sync
npx cap run android
npx cap run iosFor live reload on a device:
bash
ionic cap run android --livereload --external
ionic cap run ios --livereload --externalFor Capacitor guidance, see the skill.
capacitor-app-developmentIonic应用使用Capacitor调用原生设备功能(相机、文件系统、推送通知等),标准工作流:
bash
npm run build
npx cap sync
npx cap run android
npx cap run ios设备上热重载开发:
bash
ionic cap run android --livereload --external
ionic cap run ios --livereload --externalCapacitor使用指南请参考技能文档。
capacitor-app-developmentCapawesome Cloud
Capawesome Cloud
Capawesome Cloud provides CI/CD services for Ionic/Capacitor apps:
- Live Updates — Deploy OTA updates to Ionic/Capacitor apps instantly, without app store review.
- Native Builds — Build iOS and Android binaries in the cloud without local Xcode or Android Studio.
- App Store Publishing — Automate submissions to the Apple App Store and Google Play Store.
Visit capawesome.io for the full Capawesome ecosystem. For setup, see the skill.
capawesome-cloudCapawesome Cloud为Ionic/Capacitor应用提供CI/CD服务:
- 热更新:无需应用商店审核,即时向Ionic/Capacitor应用推送OTA更新
- 云端原生构建:无需本地安装Xcode或Android Studio,云端构建iOS和Android安装包
- 应用商店发布:自动提交应用到苹果App Store和谷歌Play商店
访问capawesome.io了解完整的Capawesome生态,配置指南请参考技能文档。
capawesome-cloudCommon Troubleshooting
常见问题排查
- : Run
ionic: command not found.npm install -g @ionic/cli - Components not rendering: Verify Ionic CSS files are imported in the global stylesheet. For standalone Angular, verify each component is imported from .
@ionic/angular/standalone - not firing: The component must be directly routed via
ionViewWillEnter. Child components do not receive lifecycle events. For React/Vue, verifyion-router-outletis the root element.IonPage - Page data not refreshing on back navigation: Use Ionic lifecycle hooks () instead of framework-native lifecycle hooks (
ionViewWillEnter,ngOnInit,useEffect). Ionic caches pages in the DOM.onMounted - Page transitions not animating: Use the framework's Ionic router integration (for Angular,
NavControllerfor React,IonReactRouterfromcreateRouterfor Vue). Standard framework routers do not trigger Ionic animations.@ionic/vue-router - CSS custom properties not applying: Ionic components use Shadow DOM. Use documented CSS custom properties (,
--background) instead of targeting internal elements.--color - Icons not showing (Angular standalone): Call from
addIcons()with the required icons and importioniconsfromIonIcon.@ionic/angular/standalone - (Vue): The Ionic component is not imported. Add the import from
Failed to resolve component: ion-*.@ionic/vue - Tab bar disappears on sub-page (React): All routes (including detail routes) must be inside the within
IonRouterOutlet.IonTabs - Form input values not updating (React): Use for
onIonInput/IonInput, notIonTextarea. Access values viaonChange.e.detail.value - Slot attribute deprecation warning (Vue): Ionic uses Web Component slots. Disable the ESLint rule: .
'vue/no-deprecated-slot-attribute': 'off'
- :运行
ionic: command not foundnpm install -g @ionic/cli - 组件不渲染:确认全局样式表中已导入Ionic的CSS文件。Angular独立组件模式下,确认每个组件都从导入
@ionic/angular/standalone - 不触发:组件必须是直接通过
ionViewWillEnter路由的页面,子组件不会收到生命周期事件。React/Vue项目确认页面根元素是ion-router-outletIonPage - 返回页面时数据不刷新:使用Ionic的生命周期钩子()代替框架原生的生命周期钩子(
ionViewWillEnter、ngOnInit、useEffect),因为Ionic会在DOM中缓存页面onMounted - 页面转场没有动画:使用框架对应的Ionic路由集成(Angular用,React用
NavController,Vue用IonReactRouter的@ionic/vue-router),标准框架路由不会触发Ionic的动画createRouter - CSS自定义属性不生效:Ionic组件使用Shadow DOM,使用官方文档提供的CSS自定义属性(、
--background),不要直接修改内部元素--color - 图标不显示(Angular独立组件模式):调用的
ionicons注册所需图标,并且从addIcons()导入@ionic/angular/standaloneIonIcon - (Vue):未导入对应的Ionic组件,从
Failed to resolve component: ion-*导入即可@ionic/vue - 进入子页面后标签栏消失(React):所有路由(包括详情页路由)都必须放在内部的
IonTabs中IonRouterOutlet - 表单输入值不更新(React):/
IonInput使用IonTextarea而不是onIonInput,通过onChange获取值e.detail.value - 插槽属性弃用警告(Vue):Ionic使用Web Component插槽,关闭ESLint规则:
'vue/no-deprecated-slot-attribute': 'off'
Related Skills
相关技能
- — Create a new Ionic app from scratch.
ionic-app-creation - — General Ionic development, full component API reference.
ionic-app-development - — Angular-specific patterns (standalone vs NgModule, navigation, forms, testing).
ionic-angular - — React-specific patterns (IonReactRouter, hooks, state management).
ionic-react - — Vue-specific patterns (composables, navigation, IonPage requirement).
ionic-vue - — Upgrade Ionic to a newer major version.
ionic-app-upgrades - — General Capacitor development.
capacitor-app-development - — Live updates, native builds, and app store publishing.
capawesome-cloud
- — 从零创建新的Ionic应用
ionic-app-creation - — Ionic通用开发指南,完整的组件API参考
ionic-app-development - — Angular专属模式(独立组件 vs NgModule、导航、表单、测试)
ionic-angular - — React专属模式(IonReactRouter、钩子、状态管理)
ionic-react - — Vue专属模式(组合式函数、导航、IonPage要求)
ionic-vue - — 升级Ionic到新的大版本
ionic-app-upgrades - — Capacitor通用开发指南
capacitor-app-development - — 热更新、云端原生构建、应用商店发布
capawesome-cloud