1e41f4b71Sopenharmony_ci# Custom Component Built-in APIs
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciCustom component built-in APIs are APIs predefined on the base class of custom components in the ArkUI framework. You can call these APIs on the instance of a custom component to obtain information, such as the UI context, about the instance.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## getUIContext
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_cigetUIContext(): UIContext
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ciObtains the **UIContext** instance.
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci**Return value**
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci| Type                                                     | Description                   |
23e41f4b71Sopenharmony_ci| --------------------------------------------------------- | ----------------------- |
24e41f4b71Sopenharmony_ci| [UIContext](../js-apis-arkui-UIContext.md#uicontext) | **UIContext** instance obtained. |
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci**Example**
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci```ts
29e41f4b71Sopenharmony_ciimport { UIContext } from '@kit.ArkUI';
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci@Entry
32e41f4b71Sopenharmony_ci@Component
33e41f4b71Sopenharmony_cistruct MyComponent {
34e41f4b71Sopenharmony_ci  aboutToAppear() {
35e41f4b71Sopenharmony_ci    let uiContext: UIContext = this.getUIContext();
36e41f4b71Sopenharmony_ci  }
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci  build() {
39e41f4b71Sopenharmony_ci    // ...
40e41f4b71Sopenharmony_ci  }
41e41f4b71Sopenharmony_ci}
42e41f4b71Sopenharmony_ci```
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci## getUniqueId<sup>12+</sup>
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_cigetUniqueId(): number
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ciObtains the unique ID of this component. This unique ID is assigned by the system to each component. If this API is called before the component is built, an invalid value **-1** is returned.
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci**Return value**
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci| Type                                                     | Description                   |
57e41f4b71Sopenharmony_ci| --------------------------------------------------------- | ----------------------- |
58e41f4b71Sopenharmony_ci| number | Unique ID of the current Component. |
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci**Example**
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci```ts
63e41f4b71Sopenharmony_ci@Entry
64e41f4b71Sopenharmony_ci@Component
65e41f4b71Sopenharmony_cistruct MyComponent {
66e41f4b71Sopenharmony_ci  aboutToAppear() {
67e41f4b71Sopenharmony_ci    let uniqueId: number = this.getUniqueId();
68e41f4b71Sopenharmony_ci  }
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci  build() {
71e41f4b71Sopenharmony_ci    // ...
72e41f4b71Sopenharmony_ci  }
73e41f4b71Sopenharmony_ci}
74e41f4b71Sopenharmony_ci```
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci## queryNavDestinationInfo
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ciqueryNavDestinationInfo(): NavDestinationInfo | undefined;
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ciQueries the **NavDestination** information of this custom component.
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci**Return value**
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci| Type                                                                      | Description     |
89e41f4b71Sopenharmony_ci| -------------------------------------------------------------------------- | --------- |
90e41f4b71Sopenharmony_ci| [NavDestinationInfo](../js-apis-arkui-observer.md#navdestinationinfo) \| undefined | **NavDestinationInfo** instance obtained. |
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci**Example**
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci```ts
95e41f4b71Sopenharmony_ciimport { uiObserver } from '@kit.ArkUI'
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci@Component
98e41f4b71Sopenharmony_ciexport struct NavDestinationExample {
99e41f4b71Sopenharmony_ci  build() {
100e41f4b71Sopenharmony_ci    NavDestination() {
101e41f4b71Sopenharmony_ci      MyComponent()
102e41f4b71Sopenharmony_ci    }
103e41f4b71Sopenharmony_ci  }
104e41f4b71Sopenharmony_ci}
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci@Component
107e41f4b71Sopenharmony_cistruct MyComponent {
108e41f4b71Sopenharmony_ci  navDesInfo: uiObserver.NavDestinationInfo | undefined
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci  aboutToAppear() {
111e41f4b71Sopenharmony_ci    // this refers to the custom node MyComponent and searches for the nearest parent node of the NavDestination type from this node upwards.
112e41f4b71Sopenharmony_ci    this.navDesInfo = this.queryNavDestinationInfo();
113e41f4b71Sopenharmony_ci    console.log('get navDestinationInfo: ' + JSON.stringify(this.navDesInfo))
114e41f4b71Sopenharmony_ci  }
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci  build() {
117e41f4b71Sopenharmony_ci    // ...
118e41f4b71Sopenharmony_ci  }
119e41f4b71Sopenharmony_ci}
120e41f4b71Sopenharmony_ci```
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci## queryNavigationInfo<sup>12+</sup>
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ciqueryNavigationInfo(): NavigationInfo | undefined
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ciQueries the **Navigation** information of this custom component.
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci**Return value**
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci| Type                                                                      | Description     |
135e41f4b71Sopenharmony_ci| -------------------------------------------------------------------------- | --------- |
136e41f4b71Sopenharmony_ci| [NavigationInfo](../js-apis-arkui-observer.md#navigationinfo12) \| undefined | **NavigationInfo** instance obtained. |
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci**Example**
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci```ts
141e41f4b71Sopenharmony_ci// index.ets
142e41f4b71Sopenharmony_ciimport { uiObserver } from '@kit.ArkUI'
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci@Entry
145e41f4b71Sopenharmony_ci@Component
146e41f4b71Sopenharmony_cistruct MainPage {
147e41f4b71Sopenharmony_ci  pathStack: NavPathStack = new NavPathStack()
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ci  build() {
150e41f4b71Sopenharmony_ci    Navigation(this.pathStack) {
151e41f4b71Sopenharmony_ci      // ...
152e41f4b71Sopenharmony_ci    }.id("NavigationId")
153e41f4b71Sopenharmony_ci  }
154e41f4b71Sopenharmony_ci}
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci@Component
158e41f4b71Sopenharmony_ciexport struct PageOne {
159e41f4b71Sopenharmony_ci  pathStack: NavPathStack = new NavPathStack()
160e41f4b71Sopenharmony_ci
161e41f4b71Sopenharmony_ci  aboutToAppear() {
162e41f4b71Sopenharmony_ci    // this refers to the custom node PageOne and searches for the nearest parent node of the Navigation type from this node upwards.
163e41f4b71Sopenharmony_ci    let navigationInfo: uiObserver.NavigationInfo | undefined = this.queryNavigationInfo()
164e41f4b71Sopenharmony_ci    console.log('get navigationInfo: ' + JSON.stringify(navigationInfo))
165e41f4b71Sopenharmony_ci    if (navigationInfo !== undefined) {
166e41f4b71Sopenharmony_ci      this.pathStack = navigationInfo.pathStack
167e41f4b71Sopenharmony_ci    }
168e41f4b71Sopenharmony_ci  }
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci  build() {
171e41f4b71Sopenharmony_ci    NavDestination() {
172e41f4b71Sopenharmony_ci      // ...
173e41f4b71Sopenharmony_ci    }.title('PageOne')
174e41f4b71Sopenharmony_ci  }
175e41f4b71Sopenharmony_ci}
176e41f4b71Sopenharmony_ci```
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci## queryRouterPageInfo<sup>12+</sup>
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ciqueryRouterPageInfo(): RouterPageInfo | undefined;
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ciObtains a **RouterPageInfo** instance.
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ci**Return value**
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci| Type                                                        | Description                        |
191e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ---------------------------- |
192e41f4b71Sopenharmony_ci| [RouterPageInfo](../js-apis-arkui-observer.md#routerpageinfo) \| undefined | **RouterPageInfo** instance obtained. |
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci**Example**
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ci```ts
197e41f4b71Sopenharmony_ciimport { uiObserver } from '@kit.ArkUI'
198e41f4b71Sopenharmony_ci
199e41f4b71Sopenharmony_ci@Entry
200e41f4b71Sopenharmony_ci@Component
201e41f4b71Sopenharmony_cistruct MyComponent {
202e41f4b71Sopenharmony_ci  aboutToAppear() {
203e41f4b71Sopenharmony_ci    let info: uiObserver.RouterPageInfo | undefined = this.queryRouterPageInfo();
204e41f4b71Sopenharmony_ci  }
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_ci  build() {
207e41f4b71Sopenharmony_ci    // ...
208e41f4b71Sopenharmony_ci  }
209e41f4b71Sopenharmony_ci}
210e41f4b71Sopenharmony_ci```
211