The Navigator component provides redirection.
This component is no longer maintained since API version 13. You are advised to use the Navigation component for page routing.
This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
active(value: boolean)
Sets whether the Navigator component is activated. If the component is activated, the corresponding navigation takes effect.
This API is supported since API version 7 and deprecated since API version 13. You are advised to use Navigation instead.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | boolean | Yes | Whether the Navigator component is activated. The value true means that the component is activated, and false means the opposite. |
params(value: object)
Sets the data that needs to be passed to the target page during redirection.
This API is supported since API version 7 and deprecated since API version 13. You are advised to use param instead.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | object | Yes | Data that needs to be passed to the target page during redirection. You can use router.getParams() to obtain the data on the target page. |
target(value: string)
Sets the path of the target page to be redirected to. The target page must be added to the main_pages.json file.
This API is supported since API version 7 and deprecated since API version 13. You are advised to use Navigation instead.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | string | Yes | Path of the target page to be redirected to. |
type(value: NavigationType)
Sets the navigation type.
This API is supported since API version 7 and deprecated since API version 13. You are advised to use Navigation instead.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | NavigationType | Yes | Navigation type. Default value: NavigationType.Push |
// code.ets
export interface NameObject {
name: string;
}
export class TextObject {
text: NameObject;
constructor(text: NameObject) {
this.text = text;
}
} import { NameObject, TextObject } from '../../code';
@Entry
@Component
struct NavigatorExample {
@State active: boolean = false
@State name: NameObject = { name: 'news' }
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
Navigator({ target: 'pages/container/navigator/Detail', type: NavigationType.Push }) {
Text('Go to ' + this.name.name + ' page')
.width('100%').textAlign(TextAlign.Center)
}.params(new TextObject(this.name)) // Pass parameters to the Detail page.
Navigator() {
Text('Back to previous page').width('100%').textAlign(TextAlign.Center)
}.active(this.active)
.onClick(() => {
this.active = true
})
}.height(150).width(350).padding(35)
}
} import { NameObject } from '../../code';
@Entry
@Component
struct DetailExample {
// Receive the input parameters of Navigator.ets.
params: Record<string, NameObject> = this.getUIContext().getRouter().getParams() as Record<string, NameObject>
@State name: NameObject = this.params.text
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
Navigator({ target: 'pages/container/navigator/Back', type: NavigationType.Push }) {
Text('Go to back page').width('100%').height(20)
}
Text('This is ' + this.name.name + ' page')
.width('100%').textAlign(TextAlign.Center)
}
.width('100%').height(200).padding({ left: 35, right: 35, top: 35 })
}
} // Back.ets
@Entry
@Component
struct BackExample {
build() {
Column() {
Navigator({ target: 'pages/container/navigator/Navigator', type: NavigationType.Back }) {
Text('Return to Navigator Page').width('100%').textAlign(TextAlign.Center)
}
}.width('100%').height(200).padding({ left: 35, right: 35, top: 35 })
}
} 