1# Navigator 2 3The **Navigator** component provides redirection. 4 5> **NOTE** 6> 7> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. 8 9 10## Child Components 11 12Supported 13 14 15## APIs 16 17Navigator(value?: {target: string, type?: NavigationType}) 18 19**Atomic service API**: This API can be used in atomic services since API version 11. 20 21**System capability**: SystemCapability.ArkUI.ArkUI.Full 22 23**Parameters** 24 25| Name| Type | Mandatory| Description | 26| ------ | -------------- | ---- | ---------------------------------------------- | 27| target | string | Yes | Path of the target page to be redirected to. | 28| type | [NavigationType](#navigationtype) | No | Navigation type.<br>Default value: **NavigationType.Push**| 29 30## NavigationType 31 32**Atomic service API**: This API can be used in atomic services since API version 11. 33 34**System capability**: SystemCapability.ArkUI.ArkUI.Full 35 36| Name | Value | Description | 37| ------- | ------- | -------------------------- | 38| Push | 1 | Navigates to the specified page in the application. | 39| Replace | 2 | Replaces the current page with another one in the application and destroys the current page.| 40| Back | 3 | Returns to the specified page. If the specified page does not exist in the stack, no response is returned. If no page is specified, the previous page is returned to.| 41 42## Attributes 43 44### active 45 46active(value: boolean) 47 48Sets whether the **Navigator** component is activated. If the component is activated, the corresponding navigation takes effect. 49 50**Atomic service API**: This API can be used in atomic services since API version 11. 51 52**System capability**: SystemCapability.ArkUI.ArkUI.Full 53 54**Parameters** 55 56| Name| Type | Mandatory| Description | 57| ------ | ------- | ---- | -------------------------- | 58| value | boolean | Yes | Whether the **Navigator** component is activated.| 59 60### params 61 62params(value: object) 63 64Sets the data that needs to be passed to the target page during redirection. 65 66**Atomic service API**: This API can be used in atomic services since API version 11. 67 68**System capability**: SystemCapability.ArkUI.ArkUI.Full 69 70**Parameters** 71 72| Name| Type | Mandatory| Description | 73| ------ | ------ | ---- | ------------------------------------------------------------ | 74| value | object | Yes | Data that needs to be passed to the target page during redirection. You can use [router.getParams()](../js-apis-router.md#routergetparams) to obtain the data on the target page.| 75 76### target 77 78target(value: string) 79 80Path of the target page to be redirected to. The target page must be added to the **main_pages.json** file. 81 82**Atomic service API**: This API can be used in atomic services since API version 11. 83 84**System capability**: SystemCapability.ArkUI.ArkUI.Full 85 86**Parameters** 87 88| Name| Type | Mandatory| Description | 89| ------ | ------ | ---- | ------------------ | 90| value | string | Yes | Path of the target page to be redirected to.| 91 92### type 93type(value: NavigationType) 94 95Sets the navigation type. 96 97**Atomic service API**: This API can be used in atomic services since API version 11. 98 99**System capability**: SystemCapability.ArkUI.ArkUI.Full 100 101**Parameters** 102 103| Name| Type | Mandatory| Description | 104| ------ | ------ | ---- | ---------------------------------------------- | 105| value | [NavigationType](#navigationtype) | Yes | Navigation type.<br>Default value: **NavigationType.Push**| 106 107 108## Example 109 110```ts 111// Navigator.ets 112@Entry 113@Component 114struct NavigatorExample { 115 @State active: boolean = false 116 @State name: NameObject = { name: 'news' } 117 118 build() { 119 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) { 120 Navigator({ target: 'pages/container/navigator/Detail', type: NavigationType.Push }) { 121 Text('Go to ' + this.name.name + ' page') 122 .width('100%').textAlign(TextAlign.Center) 123 }.params(new TextObject(this.name)) // Pass parameters to the Detail page. 124 125 Navigator() { 126 Text('Back to previous page').width('100%').textAlign(TextAlign.Center) 127 }.active(this.active) 128 .onClick(() => { 129 this.active = true 130 }) 131 }.height(150).width(350).padding(35) 132 } 133} 134 135interface NameObject { 136 name: string; 137} 138 139class TextObject { 140 text: NameObject; 141 142 constructor(text: NameObject) { 143 this.text = text; 144 } 145} 146``` 147 148```ts 149// Detail.ets 150import { router } from '@kit.ArkUI' 151 152@Entry 153@Component 154struct DetailExample { 155 // Receive the input parameters of Navigator.ets. 156 params: Record<string, NameObject> = router.getParams() as Record<string, NameObject> 157 @State name: NameObject = this.params.text 158 159 build() { 160 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) { 161 Navigator({ target: 'pages/container/navigator/Back', type: NavigationType.Push }) { 162 Text('Go to back page').width('100%').height(20) 163 } 164 165 Text('This is ' + this.name.name + ' page') 166 .width('100%').textAlign(TextAlign.Center) 167 } 168 .width('100%').height(200).padding({ left: 35, right: 35, top: 35 }) 169 } 170} 171 172interface NameObject { 173 name: string; 174} 175``` 176 177```ts 178// Back.ets 179@Entry 180@Component 181struct BackExample { 182 build() { 183 Column() { 184 Navigator({ target: 'pages/container/navigator/Navigator', type: NavigationType.Back }) { 185 Text('Return to Navigator Page').width('100%').textAlign(TextAlign.Center) 186 } 187 }.width('100%').height(200).padding({ left: 35, right: 35, top: 35 }) 188 } 189} 190``` 191 192 193