1# Navigation Transition 2 3 4Navigation transition is a transition animation that runs during the navigation from one view to another. You can customize the animation settings of the navigation transition. For details, see [Navigation Example 3](../reference/apis-arkui/arkui-ts/ts-basic-components-navigation.md#example-3). 5 6 7To implement the navigation transition, you are advised to use the [Navigation](../reference/apis-arkui/arkui-ts/ts-basic-components-navigation.md) component, complete with the [NavDestination](../reference/apis-arkui/arkui-ts/ts-basic-components-navdestination.md) component. 8 9 10Below is the complete sample code and effect. 11 12## Creating a Navigation Page 13To create a navigation page: 14 151. Use **Navigation** to create a navigation home page and create a **NavPathStack** as the navigation stack to enable transitions between different pages. 16 172. Add a **List** component to **Navigation** to define the different level-1 pages on the navigation home page. 18 193. Add an **onClick** method to the component inside the **List**, and use the **pushPathByName** method of the **NavPathStack** within it. This allows the component to transition from the current page to the page corresponding to the input parameter **name** in the routing table upon click. 20```ts 21//PageOne.ets 22@Entry 23@Component 24struct NavigationDemo { 25 @Provide('pathInfos') pathInfos: NavPathStack = new NavPathStack(); 26 private listArray: Array<string> = ['WLAN', 'Bluetooth', 'Personal Hotpot', 'Connect & Share']; 27 28 build() { 29 Column() { 30 Navigation(this.pathInfos) { 31 TextInput({ placeholder: 'Search by keyword' }) 32 .width('90%') 33 .height(40) 34 .margin({ bottom: 10 }) 35 36 // Define the level-1 navigation view through List. 37 List({ space: 12, initialIndex: 0 }) { 38 ForEach(this.listArray, (item: string) => { 39 ListItem() { 40 Row() { 41 Row() { 42 Text(`${item.slice(0, 1)}`) 43 .fontColor(Color.White) 44 .fontSize(14) 45 .fontWeight(FontWeight.Bold) 46 } 47 .width(30) 48 .height(30) 49 .backgroundColor('#a8a8a8') 50 .margin({ right: 20 }) 51 .borderRadius(20) 52 .justifyContent(FlexAlign.Center) 53 54 Column() { 55 Text(item) 56 .fontSize(16) 57 .margin({ bottom: 5 }) 58 } 59 .alignItems(HorizontalAlign.Start) 60 61 Blank() 62 63 Row() 64 .width(12) 65 .height(12) 66 .margin({ right: 15 }) 67 .border({ 68 width: { top: 2, right: 2 }, 69 color: 0xcccccc 70 }) 71 .rotate({ angle: 45 }) 72 } 73 .borderRadius(15) 74 .shadow({ radius: 100, color: '#ededed' }) 75 .width('90%') 76 .alignItems(VerticalAlign.Center) 77 .padding({ left: 15, top: 15, bottom: 15 }) 78 .backgroundColor(Color.White) 79 } 80 .width('100%') 81 .onClick(() => { 82 this.pathInfos.pushPathByName(`${item}`, 'Details page parameters')// Push the navigation destination page specified by name, with the data specified by param, to the navigation stack. 83 }) 84 }, (item: string): string => item) 85 } 86 .listDirection(Axis.Vertical) 87 .edgeEffect(EdgeEffect.Spring) 88 .sticky(StickyStyle.Header) 89 .chainAnimation(false) 90 .width('100%') 91 } 92 .width('100%') 93 .mode(NavigationMode.Auto) 94 .title('Settings') // Set the title text. 95 } 96 .size({ width: '100%', height: '100%' }) 97 .backgroundColor(0xf4f4f5) 98 } 99} 100``` 101## Creating a Navigation Subpage 102Create navigation subpage 1 as follows: 103 1041. Use **NavDestination** to create a navigation subpage **CommonPage**. 105 1062. Create a navigation stack **NavPathStack** and initialize it in **onReady** to obtain the current page stack to enable transitions between different pages. 107 1083. Add an **onClick** method to the components within the subpage and use the **pop** method of the **NavPathStack** to pop the top element of the stack and return to the previous page upon click. 109```ts 110//PageOne.ets 111 112@Builder 113export function MyCommonPageBuilder(name: string, param: string) { 114 MyCommonPage({ name: name, value: param }) 115} 116 117@Component 118export struct MyCommonPage { 119 pathInfos: NavPathStack = new NavPathStack(); 120 name: String = ''; 121 @State value: String = ''; 122 123 build() { 124 NavDestination() { 125 Column() { 126 Text(`${this.name} settings`) 127 .width('100%') 128 .fontSize(20) 129 .fontColor(0x333333) 130 .textAlign(TextAlign.Center) 131 .textShadow({ 132 radius: 2, 133 offsetX: 4, 134 offsetY: 4, 135 color: 0x909399 136 }) 137 .padding({ top: 30 }) 138 Text(`${JSON.stringify(this.value)}`) 139 .width('100%') 140 .fontSize(18) 141 .fontColor(0x666666) 142 .textAlign(TextAlign.Center) 143 .padding({ top: 45 }) 144 Button('Back') 145 .width('50%') 146 .height(40) 147 .margin({ top: 50 }) 148 .onClick(() => { 149 // Pop the top element of the stack and return to the previous page. 150 this.pathInfos.pop(); 151 }) 152 } 153 .size({ width: '100%', height: '100%' }) 154 }.title(`${this.name}`) 155 .onReady((ctx: NavDestinationContext) => { 156 // NavDestinationContext obtains the current page stack. 157 this.pathInfos = ctx.pathStack; 158 }) 159 160 } 161} 162 163 164``` 165Create navigation subpage 2 as follows: 166 1671. Use **NavDestination** to create a navigation subpage **SharePage**. 168 1692. Create a navigation stack **NavPathStack** and initialize it in **onReady** to obtain the current page stack to enable transitions between different pages. 170 1713. Add an **onClick** method to a component inside the subpage and use the **pushPathByName** method of the **NavPathStack**. This allows the component to transition from the current page to the page corresponding to the input parameter **name** in the routing table upon click. 172```ts 173//PageTwo.ets 174@Builder 175export function MySharePageBuilder(name: string, param: string) { 176 MySharePage({ name: name }) 177} 178 179@Component 180export struct MySharePage { 181 pathInfos: NavPathStack = new NavPathStack(); 182 name: String = ''; 183 private listArray: Array<string> = ['Projection', 'Print', 'VPN', 'Private DNS', 'NFC']; 184 185 build() { 186 NavDestination() { 187 Column() { 188 List({ space: 12, initialIndex: 0 }) { 189 ForEach(this.listArray, (item: string) => { 190 ListItem() { 191 Row() { 192 Row() { 193 Text(`${item.slice(0, 1)}`) 194 .fontColor(Color.White) 195 .fontSize(14) 196 .fontWeight(FontWeight.Bold) 197 } 198 .width(30) 199 .height(30) 200 .backgroundColor('#a8a8a8') 201 .margin({ right: 20 }) 202 .borderRadius(20) 203 .justifyContent(FlexAlign.Center) 204 205 Column() { 206 Text(item) 207 .fontSize(16) 208 .margin({ bottom: 5 }) 209 } 210 .alignItems(HorizontalAlign.Start) 211 212 Blank() 213 214 Row() 215 .width(12) 216 .height(12) 217 .margin({ right: 15 }) 218 .border({ 219 width: { top: 2, right: 2 }, 220 color: 0xcccccc 221 }) 222 .rotate({ angle: 45 }) 223 } 224 .borderRadius(15) 225 .shadow({ radius: 100, color: '#ededed' }) 226 .width('90%') 227 .alignItems(VerticalAlign.Center) 228 .padding({ left: 15, top: 15, bottom: 15 }) 229 .backgroundColor(Color.White) 230 } 231 .width('100%') 232 .onClick(() => { 233 this.pathInfos.pushPathByName(`${item}`, 'Parameters') 234 }) 235 }, (item: string): string => item) 236 } 237 .listDirection(Axis.Vertical) 238 .edgeEffect(EdgeEffect.Spring) 239 .sticky(StickyStyle.Header) 240 .width('100%') 241 } 242 .size({ width: '100%', height: '100%' }) 243 }.title(`${this.name}`) 244 .onReady((ctx: NavDestinationContext) => { 245 // NavDestinationContext obtains the current page stack. 246 this.pathInfos = ctx.pathStack; 247 }) 248 } 249} 250``` 251## Creating Route Navigation 252To create route navigation: 253 2541. In the project configuration file **module.json5**, add the configuration **{"routerMap": "$profile:route_map"}**. 255 2562. In the **route_map.json** file, define the global routing table. The navigation stack **NavPathStack** can push the corresponding page information onto the stack based on the name in the routing table. 257```ts 258{ 259 "routerMap" : [ 260 { 261 "name" : "WLAN", 262 "pageSourceFile" : "src/main/ets/pages/PageOne.ets", 263 "buildFunction" : "MyCommonPageBuilder" 264 }, 265 { 266 "name" : "Bluetooth", 267 "pageSourceFile" : "src/main/ets/pages/PageOne.ets", 268 "buildFunction" : "MyCommonPageBuilder" 269 }, 270 { 271 "name" : "Personal Hotpot", 272 "pageSourceFile" : "src/main/ets/pages/PageOne.ets", 273 "buildFunction" : "MyCommonPageBuilder" 274 }, 275 { 276 "name" : "Connect & Share", 277 "pageSourceFile" : "src/main/ets/pages/PageTwo.ets", 278 "buildFunction" : "MySharePageBuilder" 279 }, 280 { 281 "name" : "Projection", 282 "pageSourceFile" : "src/main/ets/pages/PageOne.ets", 283 "buildFunction" : "MyCommonPageBuilder" 284 }, 285 { 286 "name" : "Print", 287 "pageSourceFile" : "src/main/ets/pages/PageOne.ets", 288 "buildFunction" : "MyCommonPageBuilder" 289 }, 290 { 291 "name" : "VPN", 292 "pageSourceFile" : "src/main/ets/pages/PageOne.ets", 293 "buildFunction" : "MyCommonPageBuilder" 294 }, 295 { 296 "name" : "Private DNS", 297 "pageSourceFile" : "src/main/ets/pages/PageOne.ets", 298 "buildFunction" : "MyCommonPageBuilder" 299 }, 300 { 301 "name" : "NFC", 302 "pageSourceFile" : "src/main/ets/pages/PageOne.ets", 303 "buildFunction" : "MyCommonPageBuilder" 304 } 305 ] 306} 307``` 308 309 310