• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Navigation
2
3The **\<Navigation>** component is the root view container for navigation. It typically functions as the root container of a page and includes a title bar, content area, and toolbar. The content area switches between the home page content (child components of **\<Navigation>**) and non-home page content (child components of [\<NavDestination>](ts-basic-components-navdestination.md)) through routing.
4
5> **NOTE**
6>
7> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
8>
9> Since API version 11, this component supports the safe area attribute by default, with the default attribute value being **expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]))**. You can override this attribute to change the default behavior. In earlier versions, you need to use the [expandSafeArea](ts-universal-attributes-expand-safe-area.md) attribute to implement the safe area feature.
10
11
12## Child Components
13
14Supported
15
16Since API version 9, it is recommended that this component be used together with the **[\<NavRouter>](ts-basic-components-navrouter.md)** component.
17
18Since API version 10, it is recommended that this component be used together with the **[\<NavPathStack>](#navpathstack10)** component and **navDestination** attribute.
19
20## APIs
21
22### Navigation
23
24Navigation()
25
26### Navigation<sup>10+</sup>
27
28Navigation(pathInfos: NavPathStack)
29
30Binds a navigation stack to the **\<Navigation>** component.
31
32**Parameters**
33
34| Name      | Type                           | Mandatory  | Description  |
35| --------- | ------------------------------- | ---- | ------ |
36| pathInfos | [NavPathStack](#navpathstack10) | No   | Information about the navigation stack.|
37
38## Attributes
39
40In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.
41
42| Name                                | Type                                    | Description                                      |
43| ---------------------------------- | ---------------------------------------- | ---------------------------------------- |
44| title                              | [ResourceStr](ts-types.md#resourcestr)<sup>10+</sup> \| [CustomBuilder](ts-types.md#custombuilder8)\| [NavigationCommonTitle](#navigationcommontitle)<sup>9+</sup> \| [NavigationCustomTitle](#navigationcustomtitle)<sup>9+</sup> | Page title.<br>**NOTE**<br>When the NavigationCustomTitle type is used to set the height, the **titleMode** attribute does not take effect.<br>When the title string is too long: (1) If no subtitle is set, the string is scaled down, wrapped in two lines, and then clipped with an ellipsis (...); (2) If a subtitle is set, the subtitle is scaled down and then clipped with an ellipsis (...).|
45| subTitle<sup>(deprecated)</sup>    | string                                   | Subtitle of the page. If this attribute is not set, no subtitle is displayed. This attribute is deprecated since API version 9. You are advised to use **title** instead.|
46| menus                              | Array<[NavigationMenuItem](#navigationmenuitem)&gt; \| [CustomBuilder](ts-types.md#custombuilder8) | Menu items in the upper right corner of the page. If this attribute is not set, no menu item is displayed. When the value type is Array<[NavigationMenuItem](#navigationmenuitem)&gt;, the menu shows a maximum of three icons in portrait mode and a maximum of five icons in landscape mode, with excess icons (if any) placed under the automatically generated **More** icon.|
47| titleMode                          | [NavigationTitleMode](#navigationtitlemode) | Display mode of the page title bar.<br>Default value: **NavigationTitleMode.Free**|
48| toolBar<sup>(deprecated)</sup>     | [object](#object) \| [CustomBuilder](ts-types.md#custombuilder8) | Content of the toolbar. If this attribute is not set, no toolbar is displayed.<br>**items**: all items on the toolbar.<br>**NOTE**<br>Items are evenly distributed on the toolbar at the bottom. Text and icons are evenly distributed in each content area. If the text is too long, it is scaled down level by level, wrapped in two lines, and then clipped with an ellipsis (...).<br>This API is deprecated since API version 10. You are advised to use **toolbarConfiguration** instead.|
49| toolbarConfiguration<sup>10+</sup> | Array<[ToolbarItem](#toolbaritem10)&gt; \| [CustomBuilder](ts-types.md#custombuilder8) | Content of the toolbar. If this attribute is not set, no toolbar is displayed.<br>**NOTE**<br>When the value type is Array<[ToolbarItem](#ToolbarItem>, the toolbar exhibits the following features:<br>Items are evenly distributed on the toolbar at the bottom. Text and icons are evenly distributed in each content area.<br>If any item contains overlong text and there are fewer than five items, the following measures are taken: 1. Increase the item's width to accommodate the text until it is as large as the screen width; 2. Scale down the text level by level; 3. Wrap the text in two lines; 4. Clip the text with an ellipsis (...).<br>The toolbar shows a maximum of five icons in portrait mode, with excess icons (if any) placed under the automatically generated **More** icon. In landscape mode, this attribute must be used together with Array<[NavigationMenuItem](#navigationmenuitem)> of the **menus** attribute; the toolbar at the bottom is automatically hidden, and all items on the toolbar are moved to the menu in the upper right corner of the screen.<br>When the value type is [CustomBuilder](ts-types.md#custombuilder8), and the toolbar does not exhibit the preceding features except that items are evenly distributed on the toolbar at the bottom.|
50| hideToolBar                        | boolean                                  | Whether to hide the toolbar.<br>Default value: **false**<br>**true**: Hide the toolbar.<br>**false**: Show the toolbar.|
51| hideTitleBar                       | boolean                                  | Whether to hide the title bar.<br>Default value: **false**<br>**true**: Hide the title bar.<br>**false**: Show the title bar.|
52| hideBackButton                     | boolean                                  | Whether to hide the back button.<br>Default value: **false**<br>**true**: Hide the back button.<br>**false**: Show the back button.<br>The back button in the title bar of the **\<NavDestination>** component cannot be hidden.<br>**NOTE**<br>The back button works only when **titleMode** is set to **NavigationTitleMode.Mini**.|
53| navBarWidth<sup>9+</sup>           | [Length](ts-types.md#length)             | Width of the navigation bar.<br>Default value: **240**<br>Unit: vp<br>**NOTE**<br>This attribute is valid only when the **\<Navigation>** component is split.|
54| navBarPosition<sup>9+</sup>        | [NavBarPosition](#navbarposition)    | Position of the navigation bar.<br>Default value: **NavBarPosition.Start**<br>**NOTE**<br>This attribute is valid only when the **\<Navigation>** component is split.|
55| mode<sup>9+</sup>                  | [NavigationMode](#navigationmode)    | Display mode of the navigation bar.<br>Default value: **NavigationMode.Auto**<br>At the default settings, the component adapts to a single column or two columns based on the component width.<br>**NOTE**<br>Available options are **Stack**, **Split**, and **Auto**.|
56| backButtonIcon<sup>9+</sup>        | string \| [PixelMap](../apis/js-apis-image.md#pixelmap7) \| [Resource](ts-types.md#resource) | Back button icon on the navigation bar. The back button in the title bar of the **\<NavDestination>** component cannot be hidden.|
57| hideNavBar<sup>9+</sup>            | boolean                                  | Whether to hide the navigation bar. If this parameter is set to **true**, the navigation bar, including the title bar, content area, and toolbar, is hidden. In this case, if the navigation destination page is in the navigation stack, it is moved to the top of the stack and displayed. Otherwise, a blank page is displayed. From API version 9 to API version 10, this attribute takes effect only in dual-column mode. Since API version 11, this attribute takes effect in single-column, dual-column, and auto modes.<br>Default value: **false**|
58| navDestination<sup>10+</sup>       | builder: (name: string, param: unknown) => void | Builder for a **\<NavDestination>** component.<br>**NOTE**<br>The **builder** function is used, with the **name** and **param** parameters passed in. In the builder, a layer of custom components can be included outside the **\<NavDestination>** component. However, no attributes or events can be set for the custom components. Otherwise, only blank components are displayed.|
59| navBarWidthRange<sup>10+</sup>     | [[Dimension](ts-types.md#dimension10), [Dimension](ts-types.md#dimension10)] | Minimum and maximum widths of the navigation bar (valid in dual-column mode).<br>Default value: **240** for the minimum value; 40% of the component width (not greater than 432) for the maximum value<br>Unit: vp<br>Priority rules:<br>Custom value > Default value<br>Minimum value > Maximum value<br>navBar > content<br>If custom values conflict, the global value takes precedence, and the local minimum value depends on the container size.|
60| minContentWidth<sup>10+</sup>      | [Dimension](ts-types.md#dimension10)     | Minimum width of the navigation bar content area (valid in dual-column mode).<br>Default value: **360**<br>Unit: vp<br>Priority rules:<br>Custom value > Default value<br>Minimum value > Maximum value<br>navBar > content<br>If custom values conflict, the global value takes precedence, and the local minimum value depends on the container size.<br>Breakpoint calculation in Auto mode: default 600 vp = minNavBarWidth (240 vp) + minContentWidth (360 vp)|
61
62## Events
63
64| Name                                      | Description                                    |
65| ---------------------------------------- | ---------------------------------------- |
66| onTitleModeChange(callback: (titleMode: NavigationTitleMode) =&gt; void) | Called when **titleMode** is set to **NavigationTitleMode.Free** and the title bar mode changes as content scrolls.|
67| onNavBarStateChange(callback: (isVisible: boolean) =&gt; void) | Called when the navigation bar visibility status changes. The value **true** means that the navigation bar is displayed, and **false** means the opposite.|
68| onNavigationModeChange(callback: (mode: NavigationMode) =&gt; void) <sup>11+</sup>| Called when the **\<Navigation>** component is displayed for the first time or its display mode switches between single-column and dual-column.<br>**NavigationMode.Split**: The component is displayed in two columns.<br>**NavigationMode.Stack**: The component is displayed in a single column.|
69| customNavContentTransition(delegate(from: [NavContentInfo](#navcontentinfo11), to: [NavContentInfo](#navcontentinfo11), operation: [NavigationOperation](#navigationoperation11)): [NavigationAnimatedTransition](#navigationanimatedtransition11)<sup>11+</sup> | Callback of the custom transition animation.<br>**from**: parameters of the exit destination page.<br> **to**: parameters of the enter destination page.<br> **operation**: transition type.|
70
71## NavPathStack<sup>10+</sup>
72
73Implements a navigation stack.
74
75### pushPath<sup>10+</sup>
76
77pushPath(info: NavPathInfo, animated?: boolean): void
78
79Pushes the navigation destination page specified by **info** to the navigation stack.
80
81**Parameters**
82
83| Name  | Type                           | Mandatory  | Description                  |
84| ---- | ----------------------------- | ---- | -------------------- |
85| info | [NavPathInfo](#navpathinfo10) | Yes   | Information about the navigation destination page.|
86| animated<sup>11+</sup> | boolean | No   | Whether to support transition animation.<br>Default value: **true**|
87
88### pushPathByName<sup>10+</sup>
89
90pushPathByName(name: string, param: unknown, animated?: boolean): void
91
92Pushes the navigation destination page specified by **name**, with the data specified by **param**, to the navigation stack.
93
94**Parameters**
95
96| Name   | Type     | Mandatory  | Description                   |
97| ----- | ------- | ---- | --------------------- |
98| name  | string  | Yes   | Name of the navigation destination page.  |
99| param | unknown | Yes   | Detailed parameters of the navigation destination page.|
100| animated<sup>11+</sup> | boolean | No   | Whether to support transition animation.<br>Default value: **true**|
101
102### replacePath<sup>11+</sup>
103
104replacePath(info: NavPathInfo, animated?: boolean): void
105
106Replaces the top of the navigation stack with the page specified by **info**.
107
108**Parameters**
109
110| Name  | Type                           | Mandatory  | Description                  |
111| ---- | ----------------------------- | ---- | -------------------- |
112| info | [NavPathInfo](#navpathinfo10) | Yes   | Parameters of the page to replace the top of the navigation stack.|
113| animated<sup>11+</sup> | boolean | No   | Whether to support transition animation.<br>Default value: **true**|
114
115### replacePathByName<sup>11+</sup>
116
117replacePathByName(name: string, param: Object, animated?: boolean): void
118
119Replaces the top of the navigation stack with the page specified by **name**.
120
121**Parameters**
122
123| Name   | Type     | Mandatory  | Description                   |
124| ----- | ------- | ---- | --------------------- |
125| name  | string  | Yes   | Name of the navigation destination page.  |
126| param | Object | Yes   | Detailed parameters of the navigation destination page.|
127| animated<sup>11+</sup> | boolean | No   | Whether to support transition animation.<br>Default value: **true**|
128
129### removeByIndexes<sup>11+</sup>
130
131removeByIndexes(indexes: Array<number\>): number
132
133Removes the navigation destination pages specified by **indexes** from the navigation stack.
134
135**Parameters**
136
137| Name   | Type     | Mandatory  | Description                   |
138| ----- | ------- | ---- | --------------------- |
139| indexes  | Array<number\>  | Yes   | Array of indexes of the navigation destination pages to remove.  |
140
141**Return value**
142
143| Type         | Description                      |
144| ----------- | ------------------------ |
145| number | Number of the navigation destination pages removed.|
146
147### removeByName<sup>11+</sup>
148
149removeByName(name: string): number
150
151Removes the navigation destination page specified by **name** from the navigation stack.
152
153**Parameters**
154
155| Name   | Type     | Mandatory  | Description                   |
156| ----- | ------- | ---- | --------------------- |
157| name  | string  | Yes   | Name of the navigation destination page to remove.  |
158
159**Return value**
160
161| Type         | Description                      |
162| ----------- | ------------------------ |
163| number | Number of the navigation destination pages removed.|
164
165### pop<sup>10+</sup>
166
167pop(animated?: boolean): NavPathInfo | undefined
168
169Pops the top element out of the navigation stack.
170
171**Parameters**
172
173| Name  | Type                           | Mandatory  | Description                  |
174| ---- | ----------------------------- | ---- | -------------------- |
175| animated<sup>11+</sup> | boolean | No   | Whether to support transition animation.<br>Default value: **true**|
176
177**Return value**
178
179| Type         | Description                      |
180| ----------- | ------------------------ |
181| NavPathInfo | Returns the information about the navigation destination page at the top of the stack.|
182| undefined   | Returns **undefined** if the navigation stack is empty.     |
183
184### popToName<sup>10+</sup>
185
186popToName(name: string, animated?: boolean): number
187
188Returns the navigation stack to the first navigation destination page that matches the value of **name**.
189
190**Parameters**
191
192| Name  | Type    | Mandatory  | Description                 |
193| ---- | ------ | ---- | ------------------- |
194| name | string | Yes   | Name of the navigation destination page.|
195| animated<sup>11+</sup> | boolean | No   | Whether to support transition animation.<br>Default value: **true**|
196
197**Return value**
198
199| Type    | Description                                      |
200| ------ | ---------------------------------------- |
201| number | Returns the index of the first navigation destination page that matches the value of **name** if it exists in the navigation stack; returns **-1** otherwise.|
202
203### popToIndex<sup>10+</sup>
204
205popToIndex(index: number, animated?: boolean): void
206
207Returns the navigation stack to the page specified by **index**.
208
209**Parameters**
210
211| Name   | Type    | Mandatory  | Description                    |
212| ----- | ------ | ---- | ---------------------- |
213| index | number | Yes   | Index of the navigation destination page.|
214| animated<sup>11+</sup> | boolean | No   | Whether to support transition animation.<br>Default value: **true**|
215
216### moveToTop<sup>10+</sup>
217
218moveToTop(name: string, animated?: boolean): number
219
220Moves to the top of the navigation stack the first navigation destination page that matches the value of **name**.
221
222**Parameters**
223
224| Name  | Type    | Mandatory  | Description                 |
225| ---- | ------ | ---- | ------------------- |
226| name | string | Yes   | Name of the navigation destination page.|
227| animated<sup>11+</sup> | boolean | No   | Whether to support transition animation.<br>Default value: **true**|
228
229**Return value**
230
231| Type    | Description                                      |
232| ------ | ---------------------------------------- |
233| number | Returns the index of the first navigation destination page that matches the value of **name** if it exists in the navigation stack; returns **-1** otherwise.|
234
235### moveIndexToTop<sup>10+</sup>
236
237moveIndexToTop(index: number, animated?: boolean): void
238
239Moves to the top of the navigation stack the navigation destination page that matches the value of **index**.
240
241**Parameters**
242
243| Name   | Type    | Mandatory  | Description                    |
244| ----- | ------ | ---- | ---------------------- |
245| index | number | Yes   | Index of the navigation destination page.|
246| animated<sup>11+</sup> | boolean | No   | Whether to support transition animation.<br>Default value: **true**|
247
248### clear<sup>10+</sup>
249
250clear(animated?: boolean): void
251
252Clears the navigation stack.
253
254**Parameters**
255
256| Name   | Type    | Mandatory  | Description                    |
257| ----- | ------ | ---- | ---------------------- |
258| animated<sup>11+</sup> | boolean | No   | Whether to support transition animation.<br>Default value: **true**|
259
260### getAllPathName<sup>10+</sup>
261
262getAllPathName(): Array<string\>
263
264Obtains the names of all navigation destination pages in the navigation stack.
265
266**Return value**
267
268| Type            | Description                        |
269| -------------- | -------------------------- |
270| Array<string\> | Names of all navigation destination pages in the navigation stack.|
271
272### getParamByIndex<sup>10+</sup>
273
274getParamByIndex(index: number): unknown | undefined
275
276Obtains the parameter information of the navigation destination page that matches the value of **index**.
277
278**Parameters**
279
280| Name   | Type    | Mandatory  | Description                    |
281| ----- | ------ | ---- | ---------------------- |
282| index | number | Yes   | Index of the navigation destination page.|
283
284**Return value**
285
286| Type       | Description                        |
287| --------- | -------------------------- |
288| unknown   | Returns the parameter information of the matching navigation destination page.|
289| undefined | Returns **undefined** if the passed index is invalid.    |
290
291### getParamByName<sup>10+</sup>
292
293getParamByName(name: string): Array<unknown\>
294
295Obtains the parameter information of all the navigation destination pages that match the value of **name**.
296
297**Parameters**
298
299| Name  | Type    | Mandatory  | Description                 |
300| ---- | ------ | ---- | ------------------- |
301| name | string | Yes   | Name of the navigation destination page.|
302
303**Return value**
304
305| Type             | Description                               |
306| --------------- | --------------------------------- |
307| Array<unknown\> | Parameter information of all the matching navigation destination pages.|
308
309### getIndexByName<sup>10+</sup>
310
311getIndexByName(name: string): Array<number\>
312
313Obtains the indexes of all the navigation destination pages that match the value of **name**.
314
315**Parameters**
316
317| Name  | Type    | Mandatory  | Description                 |
318| ---- | ------ | ---- | ------------------- |
319| name | string | Yes   | Name of the navigation destination page.|
320
321**Return value**
322
323| Type            | Description                               |
324| -------------- | --------------------------------- |
325| Array<number\> | Indexes of all the matching navigation destination pages.|
326
327### size<sup>10+</sup>
328
329size(): number
330
331Obtains the stack size.
332
333**Return value**
334
335| Type    | Description    |
336| ------ | ------ |
337| number | Stack size.|
338
339### disableAnimation<sup>11+</sup>
340
341disableAnimation(value: boolean): void
342
343Disables or enables the transition animation in the **\<Navigation>** component.
344
345**Parameters**
346
347| Name   | Type    | Mandatory  | Description                    |
348| ----- | ------ | ---- | ---------------------- |
349| value | boolean | No   | Whether to disable the transition animation.<br>Default value: **false**|
350
351## NavPathInfo<sup>10+</sup>
352
353Provides the navigation page information.
354
355### constructor
356
357constructor(name: string, param: unknown)
358
359**Parameters**
360
361| Name   | Type     | Mandatory  | Description                   |
362| ----- | ------- | ---- | --------------------- |
363| name  | string  | Yes   | Name of the navigation destination page.  |
364| param | unknown | No   | Detailed parameters of the navigation destination page.|
365
366## NavContentInfo<sup>11+</sup>
367
368Provides the destination information.
369
370**Parameters**
371
372| Name | Type | Mandatory | Description |
373|-------|-------|------|-------|
374| name | string | No| Name of the navigation destination. If the view is a root view (**NavBar**), the return value is **undefined**.|
375| index | number | Yes| Index of the navigation destination in the navigation stack. If the view is a root view (**NavBar**), the return value is **-1**.|
376| mode | [NavDestinationMode](ts-basic-components-navdestination.md#navdestinationmode11) | No| Mode of the navigation destination. If the view is a root view (**NavBar**), the return value is **undefined**.|
377
378## NavigationAnimatedTransition<sup>11+</sup>
379
380Defines the custom transition animation protocol. You need to implement this protocol to define the redirection animation of the navigation route.
381
382**Parameters**
383| Name| Type| Mandatory| Description|
384|------|-----|-----|------|
385| timeout | number | No| Animation timeout time.<br> Unit: ms<br> Default value: **1000**|
386| transition | (transitionProxy : [NavigationTransitionProxy](#navigationtransitionproxy-11)): void | Yes| Callback for executing the custom transition animation.<br> **transitionProxy**: proxy for the custom transition animation.|
387| onTransitionEnd | (success: boolean):void | No| Callback invoked when the transition is complete.<br> **success**: whether the transition is successful.|
388
389## NavigationTransitionProxy <sup>11+</sup>
390
391Implements a custom transition animation proxy.
392
393**Parameters**
394
395| Name| Type | Mandatory| Description |
396|------|-------|-----|-------|
397| from | [NavContentInfo](#navcontentinfo11) | Yes| Information about the exit page.|
398| to | [NavContentInfo](#navcontentinfo11) | Yes| Information about the enter page.|
399
400### finishTransition
401
402Finishes this custom transition animation. This API must be manually called to end the animation. Otherwise, the system ends the animation when the timeout expires.
403
404## NavigationMenuItem
405
406| Name    | Type           | Mandatory  | Description             |
407| ------ | ------------- | ---- | --------------- |
408| value  | string        | Yes   | Text of the menu item. Its visibility varies by the API version.<br>API version 9: visible.<br> API version 10: invisible. |
409| icon   | string        | No   | Icon path of the menu item.|
410| action | () =&gt; void | No   | Callback invoked when the menu item is selected.  |
411
412## object
413
414| Name    | Type           | Mandatory  | Description             |
415| ------ | ------------- | ---- | --------------- |
416| value  | string        | Yes   | Text of a toolbar item.  |
417| icon   | string        | No   | Icon path of a toolbar item.|
418| action | () =&gt; void | No   | Callback invoked when a toolbar item is selected.  |
419
420## ToolbarItem<sup>10+</sup>
421
422| Name        | Type                                      | Mandatory  | Description                                      |
423| ---------- | ---------------------------------------- | ---- | ---------------------------------------- |
424| value      | ResourceStr                              | Yes   | Text of a toolbar item.                           |
425| icon       | ResourceStr                              | No   | Icon path of a toolbar item.                         |
426| action     | () =&gt; void                            | No   | Callback invoked when a toolbar item is selected.                           |
427| status     | [ToolbarItemStatus](#toolbaritemstatus10) | No   | Status of a toolbar item.<br>Default value: **ToolbarItemStatus.NORMAL**|
428| activeIcon | ResourceStr                              | No   | Icon path of the toolbar item in the active state.               |
429
430## ToolbarItemStatus<sup>10+</sup>
431
432| Name      | Description                                      |
433| -------- | ---------------------------------------- |
434| NORMAL   | Normal state. In this state, the toolbar item takes on the default style and can switch to another state-specific style by responding to the hover, press, and focus events.|
435| DISABLED | Disabled state. In this state, the toolbar item is disabled and does not allow for user interactions.|
436| ACTIVE   | Active state. In this state, the toolbar item can update its icon to the one specified by **activeIcon** by responding to a click event.|
437
438## NavigationTitleMode
439
440| Name  | Description                                      |
441| ---- | ---------------------------------------- |
442| Free | When the content is a scrollable component, the main title shrinks as the content scrolls down (the subtitle fades out with its size remaining unchanged) and restores as the content scrolls up to the top.<br>**NOTE**<br>The size linkage effect works only when **title** is set to **ResourceStr** or **NavigationCommonTitle**. If **title** is set to any other value type, the main title changes in mere location when pulled down.|
443| Mini | The title is fixed at mini mode.                               |
444| Full | The title is fixed at full mode.                               |
445
446## NavigationCommonTitle
447
448| Name  | Type    | Mandatory  | Description    |
449| ---- | ------ | ---- | ------ |
450| main | string | Yes   | Main title.|
451| sub  | string | Yes   | Subtitle.|
452
453## NavigationCustomTitle
454
455| Name     | Type                                      | Mandatory  | Description      |
456| ------- | ---------------------------------------- | ---- | -------- |
457| builder | [CustomBuilder](ts-types.md#custombuilder8) | Yes   | Content of the title bar.|
458| height  | [TitleHeight](#titleheight) \| [Length](ts-types.md#length) | Yes   | Height of the title bar.|
459
460## NavBarPosition
461
462| Name   | Description              |
463| ----- | ---------------- |
464| Start | When two columns are displayed, the main column is at the start of the main axis.|
465| End   | When two columns are displayed, the main column is at the end of the main axis.|
466
467## NavigationMode
468
469| Name | Description                                                        |
470| ----- | ------------------------------------------------------------ |
471| Stack | The navigation bar and content area are displayed independently of each other, which are equivalent to two pages.                    |
472| Split | The navigation bar and content area are displayed in different columns.<br>The values of **navBarWidthRange** are represented by [minNavBarWidth,maxNavBarWidth].<br>1. When the value of **navBarWidth** is beyond the value range specified by **navBarWidthRange**, **navBarWidth** is set according to the following rules:<br>Value of **navBarWidth** < Value of **minNavBarWidth**: The value of **navBarWidth** is changed to that of **minNavBarWidth**.<br>Value of **navBarWidth** > Value of **maxNavBarWidth** and Result of [Component width - Value of **minContentWidth** - Divider width (1 vp)] > Value of **maxNavBarWidth**: The value of **navBarWidth** is changed to that of **maxNavBarWidth**.<br>Value of **navBarWidth** > Value of **maxNavBarWidth** and Result of [Component width - Value of **minContentWidth** - Divider width (1 vp)] < Value of **maxNavBarWidth**: The value of **navBarWidth** is changed to that of **minNavBarWidth**.<br>Value of **navBarWidth** > Value of **maxNavBarWidth** and Component width - Value of **minContentWidth** - Divider width (1 vp) is within the value range specified by **navBarWidthRange**: The value of **navBarWidth** is changed to Component width - Value of **minContentWidth** - Divider width (1 vp).<br>2. When the value of **navBarWidth** is within the value range specified by **navBarWidthRange**, **navBarWidth** is set according to the following rules:<br>Value of **minNavBarWidth** + Value of **minContentWidth** + Divider width (1 vp) > = Component width: The value of **navBarWidth** is changed to that of **minNavBarWidth**.<br>Value of **minNavBarWidth** + Value of **minContentWidth** + Divider width (1 vp) < Component width and Value of **navBarWidth** + Value of **minContentWidth** + Divider width (1 vp) > = Component width: The value of **navBarWidth** is changed to Component width - Value of **minContentWidth** - Divider width (1 vp).<br>Value of **minNavBarWidth** + Value of **minContentWidth** + Divider width (1 vp) < Component width and Value of **navBarWidth** + Value of **minContentWidth** + Divider width (1 vp) < Component width: The value of **navBarWidth** is the set value. <br>3. When the component size is decreased, the content area is shrunk until its width reaches the value defined by **minContentWidth**, and then the navigation bar is shrunk until its width reaches the value defined by **minNavBarWidth**; if the component size is further decreased, the content area is further shrunk until it disappears, and then navigation bar is shrunk.<br>4. When the navigation bar is set to a fixed size and the component size is continuously decreased, the navigation bar is shrunk.<br>5. If only **navBarWidth** is set, the width of the navigation bar is fixed at the value of **navBarWidth**, and the divider cannot be dragged.|
473| Auto  | In API version 9 and earlier versions: If the window width is greater than or equal to 520 vp, the Split mode is used; otherwise, the Stack mode is used.<br>In API version 10 and later versions: If the window width is greater than or equal to 600 vp, the Split mode is used; otherwise, the Stack mode is used. 600 vp = minNavBarWidth (240 vp) + minContentWidth (360 vp).|
474
475## TitleHeight
476
477| Name         | Description                        |
478| ----------- | -------------------------- |
479| MainOnly    | Recommended height (56 vp) of the title bar when only the main title is available.     |
480| MainWithSub | Recommended height (82 vp) of the title bar when both the main title and subtitle exist.|
481
482## NavigationOperation<sup>11+</sup>
483| Name   | Description |
484|---------|------|
485|PUSH | The transition is enter transition.|
486|POP | The transition is exit transition.|
487| REPLACE | The transition is page replacement.|
488
489>  **NOTE**
490>
491>  Among the scrollable components, only **\<List>** is supported.
492
493
494## Example
495
496### Example 1
497
498```ts
499// xxx.ets
500class A {
501  text: string = ''
502  num: number = 0
503}
504
505@Entry
506@Component
507struct NavigationExample {
508  private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
509  @State currentIndex: number = 0
510
511  @Builder NavigationTitle() {
512    Column() {
513      Text('Title')
514        .fontColor('#182431')
515        .fontSize(30)
516        .lineHeight(41)
517        .fontWeight(700)
518      Text('subtitle')
519        .fontColor('#182431')
520        .fontSize(14)
521        .lineHeight(19)
522        .opacity(0.4)
523        .margin({ top: 2, bottom: 20 })
524    }.alignItems(HorizontalAlign.Start)
525  }
526
527  @Builder NavigationMenus() {
528    Row() {
529      Image('resources/base/media/ic_public_add.svg')
530        .width(24)
531        .height(24)
532      Image('resources/base/media/ic_public_add.svg')
533        .width(24)
534        .height(24)
535        .margin({ left: 24 })
536      Image('common/ic_public_more.svg')
537        .width(24)
538        .height(24)
539        .margin({ left: 24 })
540    }
541  }
542
543  build() {
544    Column() {
545      Navigation() {
546        TextInput({ placeholder: 'search...' })
547          .width('90%')
548          .height(40)
549          .backgroundColor('#FFFFFF')
550          .margin({ top: 8 })
551
552        List({ space: 12, initialIndex: 0 }) {
553          ForEach(this.arr, (item: number) => {
554            ListItem() {
555              Text('' + item)
556                .width('90%')
557                .height(72)
558                .backgroundColor('#FFFFFF')
559                .borderRadius(24)
560                .fontSize(16)
561                .fontWeight(500)
562                .textAlign(TextAlign.Center)
563            }
564          }, (item: number) => item.toString())
565        }
566        .height(324)
567        .width('100%')
568        .margin({ top: 12, left: '10%' })
569      }
570      .title(this.NavigationTitle)
571      .menus(this.NavigationMenus)
572      .titleMode(NavigationTitleMode.Full)
573      .toolbarConfiguration([
574        {
575          value: $r("app.string.navigation_toolbar_add"),
576          icon: $r("app.media.ic_public_highlightsed")
577        },
578        {
579          value: $r("app.string.navigation_toolbar_app"),
580          icon: $r("app.media.ic_public_highlights")
581        },
582        {
583          value: $r("app.string.navigation_toolbar_collect"),
584          icon: $r("app.media.ic_public_highlights")
585        }
586      ])
587      .hideTitleBar(false)
588      .hideToolBar(false)
589      .onTitleModeChange((titleModel: NavigationTitleMode) => {
590        console.info('titleMode' + titleModel)
591      })
592    }.width('100%').height('100%').backgroundColor('#F1F3F5')
593  }
594}
595```
596
597![en-us_image_navigation](figures/en-us_image_navigation.png)
598
599
600
601### Example 2
602```ts
603// Index.ets
604import { PageOneTmp } from './PageOne'
605import { pageTwoTmp } from './PageTwo'
606import { Pages }  from './PageTwo'
607
608@Entry
609@Component
610struct NavigationExample {
611  @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack()
612
613  @Builder
614  PageMap(name: string) {
615    if (name === 'pageOne') {
616      PageOneTmp()
617    } else if (name === 'pageTwo') {
618      pageTwoTmp({ names: name, values: this.pageInfos } as Pages)
619    }
620  }
621
622  build() {
623    Navigation(this.pageInfos) {
624      Column() {
625        Button('pushPath', { stateEffect: true, type: ButtonType.Capsule })
626          .width('80%')
627          .height(40)
628          .margin(20)
629          .onClick(() => {
630            this.pageInfos.pushPath({ name:'pageOne'}) // Push the navigation destination page specified by name to the navigation stack.
631          })
632      }
633    }.title('NavIndex').navDestination(this.PageMap)
634  }
635}
636```
637```ts
638// PageOne.ets
639class TmpClass{
640  count:number=10
641}
642@Component
643export struct PageOneTmp {
644  @Consume('pageInfos') pageInfos: NavPathStack;
645
646  build() {
647    NavDestination() {
648      Column() {
649        Button('pushPathByName', { stateEffect: true, type: ButtonType.Capsule })
650          .width('80%')
651          .height(40)
652          .margin(20)
653          .onClick(() => {
654            let tmp = new TmpClass()
655            this.pageInfos.pushPathByName('pageTwo', tmp) // Push the navigation destination page specified by name to the navigation stack, with the data specified by param passed in.
656          })
657        Button('popToname', { stateEffect: true, type: ButtonType.Capsule })
658          .width('80%')
659          .height(40)
660          .margin(20)
661          .onClick(() => {
662            this.pageInfos.popToName('pageTwo') // Return the navigation stack to the first navigation destination page that matches the value of name.
663            console.log('popToName' + JSON.stringify(this.pageInfos), 'Return value' + JSON.stringify(this.pageInfos.popToName('pageTwo')))
664          })
665        Button('popToIndex', { stateEffect: true, type: ButtonType.Capsule })
666          .width('80%')
667          .height(40)
668          .margin(20)
669          .onClick(() => {
670            this.pageInfos.popToIndex(1) // Return the navigation stack to the navigation destination page that matches the value of index.
671            console.log('popToIndex' + JSON.stringify(this.pageInfos))
672          })
673        Button('moveToTop', { stateEffect: true, type: ButtonType.Capsule })
674          .width('80%')
675          .height(40)
676          .margin(20)
677          .onClick(() => {
678            this.pageInfos.moveToTop('pageTwo') // Move to the top of the navigation stack the first navigation destination page that matches the value of name.
679            console.log('moveToTop' + JSON.stringify(this.pageInfos), 'Return value' + JSON.stringify(this.pageInfos.moveToTop('pageTwo')))
680          })
681        Button('moveIndexToTop', { stateEffect: true, type: ButtonType.Capsule })
682          .width('80%')
683          .height(40)
684          .margin(20)
685          .onClick(() => {
686            this.pageInfos.moveIndexToTop(1) // Move to the top of the navigation stack the navigation destination page that matches the value of index.
687            console.log('moveIndexToTop' + JSON.stringify(this.pageInfos))
688          })
689        Button('clear', { stateEffect: true, type: ButtonType.Capsule })
690          .width('80%')
691          .height(40)
692          .margin(20)
693          .onClick(() => {
694            this.pageInfos.clear() // Clear the navigation stack.
695          })
696        Button('get', { stateEffect: true, type: ButtonType.Capsule })
697          .width('80%')
698          .height(40)
699          .margin(20)
700          .onClick(() => {
701            console.log('-------------------')
702            console.log('Obtained the names of all pages in the navigation stack', JSON.stringify(this.pageInfos.getAllPathName()))
703            console.log('Obtained parameter information of the navigation destination page specified by index', JSON.stringify(this.pageInfos.getParamByIndex(1)))
704            console.log('Obtained parameter information of all the navigation destination pages specified by name', JSON.stringify(this.pageInfos.getParamByName('pageTwo')))
705            console.log('Obtained the index information of all the navigation destination pages specified by name', JSON.stringify(this.pageInfos.getIndexByName('pageOne'))))
706            console.log ('Obtained the stack size', JSON.stringify (this.pageInfos.size ()))
707          })
708      }.width('100%').height('100%')
709    }.title('pageOne')
710    .onBackPressed(() => {
711      const popDestinationInfo = this.pageInfos.pop() // Pops the top element out of the navigation stack.
712      console.log('pop' + 'Return value' + JSON.stringify(popDestinationInfo))
713      return true
714    })
715  }
716}
717```
718```ts
719// PageTwo.ets
720export class Pages {
721  names: string = ""
722  values: NavPathStack | null = null
723}
724
725@Builder
726export function pageTwoTmp(info: Pages) {
727  NavDestination() {
728    Column() {
729      Button('pushPathByName', { stateEffect: true, type: ButtonType.Capsule })
730        .width('80%')
731        .height(40)
732        .margin(20)
733        .onClick(() => {
734          (info.values as NavPathStack).pushPathByName('pageOne', null)
735        })
736    }.width('100%').height('100%')
737  }.title('pageTwo')
738  .onBackPressed(() => {
739    (info.values as NavPathStack).pop()
740    return true
741  })
742}
743```
744![navigation.gif](figures/navigation.gif)
745
746### Example 3
747
748```ts
749// Index.ets
750import { CustomTransition, AnimateCallback } from './CustomNavigationUtils'
751import { pageOneTmp } from './PageOne'
752import {PageTwoTemp} from './PageTwo'
753
754@Entry
755@Component
756struct NavigationExample {
757  @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack()
758
759  @Builder
760  PageMap(name: string) {
761    if (name === 'pageOne') {
762      pageOneTmp()
763    } else if (name === 'pageTwo') {
764      PageTwoTemp()
765    }
766  }
767
768  aboutToAppear() {
769    if (this.pageInfos === undefined) {
770      this.pageInfos = new NavPathStack();
771    }
772    this.pageInfos.pushPath({name: 'pageOne'}, false)
773  }
774
775  build() {
776    Navigation(this.pageInfos) {
777    }.title('NavIndex').navDestination(this.PageMap)
778    .hideNavBar(true)
779    .customNavContentTransition((from: NavContentInfo, to: NavContentInfo, operation: NavigationOperation) => {
780      if (from.mode == NavDestinationMode.DIALOG || to.mode == NavDestinationMode.DIALOG) {
781        return undefined;
782      }
783      console.log(`current info: ${to.name}, index: ${to.index}, mode: ${to.mode}`);
784      console.log(`pre info: ${from.name}, index: ${from.index}, mode: ${from.mode}`);
785      console.log(`operation: ${operation}`)
786      if (from.index === -1 || to.index === -1) {
787        return undefined;
788      }
789      let customAnimation: NavigationAnimatedTransition = {
790        onTransitionEnd: (isSuccess: boolean)=>{
791          console.log(`current transition result is ${isSuccess}`);
792        },
793        timeout: 700,
794        transition: (transitionProxy: NavigationTransitionProxy)=>{
795          console.log("trigger transition callback");
796          let fromParam: AnimateCallback = CustomTransition.getInstance().getAnimateParam(from.name);
797          let toParam: AnimateCallback = CustomTransition.getInstance().getAnimateParam(to.name);
798          fromParam.start(operation == NavigationOperation.PUSH, true);
799          toParam.start(operation == NavigationOperation.PUSH, false);
800          animateTo({duration: 400, onFinish: ()=>{
801            fromParam.onFinish(operation === NavigationOperation.PUSH, true);
802            toParam.onFinish(operation === NavigationOperation.PUSH, true);
803            transitionProxy.finishTransition();
804          }}, ()=>{
805            fromParam.finish(operation === NavigationOperation.PUSH, true)
806            toParam.finish(operation === NavigationOperation.PUSH, false);
807          })
808        }
809      };
810      return customAnimation;
811    })
812  }
813}
814```
815
816```ts
817// PageOne.ets
818import {CustomTransition} from './CustomNavigationUtils'
819
820@Component
821export struct pageOneTmp {
822  @Consume('pageInfos') pageInfos: NavPathStack
823  @State x: number = 0
824  @State scaleVal: number = 1
825
826  aboutToAppear() {
827    CustomTransition.getInstance().registerNavParam('pageOne', (isPush: boolean, isExit: boolean) => {
828      this.x = isExit ? 0 : 300;
829    }, (isPush: boolean, isExit: boolean)=> {
830      this.x = isExit ? -300 : 0;
831    }, (isPush: boolean, isExit: boolean) => {
832      this.x = 0;
833    }, 200);
834  }
835
836  build() {
837    NavDestination() {
838      Column() {
839        Button('pushPathByName', { stateEffect: true, type: ButtonType.Capsule })
840          .width('80%')
841          .height(40)
842          .margin(20)
843          .onClick(() => {
844            this.pageInfos.pushPathByName('pageTwo', null) // Push the navigation destination page specified by name to the navigation stack, with the data specified by param passed in.
845          })
846      }.width('100%').height('100%')
847    }.title('pageOne')
848    .mode(NavDestinationMode.STANDARD)
849    .onBackPressed(() => {
850      const popDestinationInfo = this.pageInfos.pop() // Pops the top element out of the navigation stack.
851      console.log('pop' + 'Return value' + JSON.stringify(popDestinationInfo))
852      return true
853    })
854    .onDisAppear(()=>{
855      let names = this.pageInfos.getAllPathName();
856      if (names.includes('pageOne')) {
857        return;
858      }
859      CustomTransition.getInstance().unRegisterNavParam('pageOne')
860    })
861    .translate({x: this.x, y: 0, z: 0})
862    .backgroundColor(Color.White)
863  }
864}
865```
866```ts
867// PageTwo.ets
868import {CustomTransition} from './CustomNavigationUtils'
869
870@Component
871export struct PageTwoTemp {
872  @Consume('pageInfos') pageInfos: NavPathStack
873  @State x: number = 300
874
875  aboutToAppear() {
876    CustomTransition.getInstance().registerNavParam('pageTwo', (isPush: boolean, isExit: boolean)=>{
877      console.log("current page is pageOne")
878      this.x = isExit ? 0 : 300;
879    }, (isPush: boolean, isExit: boolean)=>{
880      this.x = isExit ? -300 : 0;
881    }, (isPush: boolean, isExit: boolean) => {
882      this.x = 0;
883    }, 200)
884  }
885
886  build() {
887    NavDestination() {
888      Column() {
889        Button('pushPathByName', { stateEffect: true, type: ButtonType.Capsule })
890          .width('80%')
891          .height(40)
892          .margin(20)
893          .onClick(() => {
894            this.pageInfos.pushPathByName('pageOne', null) // Push the navigation destination page specified by name to the navigation stack, with the data specified by param passed in.
895          })
896      }.width('100%').height('100%')
897    }.title('pageTwo')
898    .onBackPressed(() => {
899      const popDestinationInfo = this.pageInfos.pop() // Pops the top element out of the navigation stack.
900      console.log('pop' + 'Return value' + JSON.stringify(popDestinationInfo))
901      return true
902    })
903    .onDisAppear(()=>{
904      let names = this.pageInfos.getAllPathName();
905      if (names.includes('pageTwo')) {
906        return;
907      }
908      CustomTransition.getInstance().unRegisterNavParam('pageTwo')
909    })
910    .translate({x: this.x})
911    .backgroundColor(Color.White)
912  }
913}
914```
915```ts
916// CustomNavigationUtils.ts
917export interface AnimateCallback {
918  finish: (isPush: boolean, isExit: boolean) => void;
919  start: (isPush: boolean, isExit: boolean) => void;
920  onFinish: (isPush: boolean, isExit: boolean) => void
921  timeout: number;
922}
923const customTransitionMap: Map<string, AnimateCallback> = new Map()
924export class CustomTransition {
925  private constructor() {
926
927  }
928
929  static delegate = new CustomTransition();
930
931  static getInstance() {
932    return this.delegate;
933  }
934
935  registerNavParam(name: string, startCallback: (operation: boolean, isExit: boolean) => void,
936                   endCallback:(operation: boolean, isExit: boolean) => void,
937                   onFinish: (opeation: boolean, isExit: boolean) => void, timeout: number): void {
938
939    if (customTransitionMap.has(name)) {
940      let param = customTransitionMap.get(name);
941      param.start = startCallback;
942      param.finish = endCallback;
943      param.timeout = timeout;
944      param.onFinish = onFinish;
945      return;
946    }
947    let params: AnimateCallback = {timeout: timeout, start: startCallback, finish: endCallback, onFinish: onFinish};
948    customTransitionMap.set(name, params);
949  }
950
951  unRegisterNavParam(name: string): void {
952    customTransitionMap.delete(name);
953  }
954
955  getAnimateParam(name: string): AnimateCallback {
956    let result: AnimateCallback = {
957      start: customTransitionMap.get(name).start,
958      finish: customTransitionMap.get(name).finish,
959      timeout: customTransitionMap.get(name).timeout,
960      onFinish: customTransitionMap.get(name).onFinish
961    };
962    return result;
963  }
964}
965```
966![customNavigation.gif](figures/customNavigation.gif)
967