1e41f4b71Sopenharmony_ci# NavRouter
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **\<NavRouter>** component provides default processing logic for responding to clicks, eliminating the need for manual logic definition.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> This component is supported since API version 9. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## Child Components
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ciThis component must contain two child components, the second of which must be **[\<NavDestination>](ts-basic-components-navdestination.md)**.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci> **NOTE**
14e41f4b71Sopenharmony_ci>
15e41f4b71Sopenharmony_ci>  
16e41f4b71Sopenharmony_ci> 1. If there is only one child component, the navigation to the **\<NavDestination>** component does not work.
17e41f4b71Sopenharmony_ci> 2. If there is only the **\<NavDestination>** child component, the navigation does not work.
18e41f4b71Sopenharmony_ci> 3. If there are more than two child components, the excess child components are not displayed.
19e41f4b71Sopenharmony_ci> 4. If the second child component is not **\<NavDestination>**, the navigation does not work.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci## APIs
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci### NavRouter
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ciNavRouter()
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci### NavRouter<sup>10+</sup>
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ciNavRouter(value: RouteInfo)
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ciProvides route information so that clicking the **\<NavRouter>** component redirects the user to the specified navigation destination page.
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci**Parameters**
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci| Name    | Type                               | Mandatory  | Description         |
40e41f4b71Sopenharmony_ci| ------- | ----------------------------------- | ---- | ------------- |
41e41f4b71Sopenharmony_ci| value   | [RouteInfo](#routeinfo10) | No   | Route information.|
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci## Attributes
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ciIn addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci### mode
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_cimode(mode: NavRouteMode)
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ciSets the route mode used for redirecting the user from the **\<NavRouter>** component to the specified navigation destination page.
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci**Parameters**
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci| Name                          | Type                                    | Mandatory                                  | Description                                      |
60e41f4b71Sopenharmony_ci| ----------------------------- | ---------------------------------------- | ---------------------------------------- | ---------------------------------------- |
61e41f4b71Sopenharmony_ci| mode                  | [NavRouteMode](#navroutemode)                                  | Yes                                | Route mode used for redirection.<br>Default value: **NavRouteMode.PUSH_WITH_RECREATE**|
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci## RouteInfo<sup>10+</sup>
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci| Name                | Type                                                    | Mandatory| Description                                                        |
68e41f4b71Sopenharmony_ci| -------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
69e41f4b71Sopenharmony_ci| name             | string            | Yes  | Name of the navigation destination page to be redirected to.|
70e41f4b71Sopenharmony_ci| param             | unknown            | No  | Parameter transferred during redirection.|
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci## NavRouteMode
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci| Name   | Description              |
77e41f4b71Sopenharmony_ci| ----- | ---------------- |
78e41f4b71Sopenharmony_ci| PUSH_WITH_RECREATE | The new navigation destination page replaces the current one. The current page is destroyed, but the information about this page is retained in the navigation stack.|
79e41f4b71Sopenharmony_ci| PUSH   | The new navigation destination page overwrites the current one. The current page is not destroyed, and the information about this page is retained in the navigation stack.|
80e41f4b71Sopenharmony_ci| REPLACE   | The new navigation destination page replaces the current one. The current page is destroyed, and the information about this page is removed from the navigation stack.|
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci## Events
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci### onStateChange
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_cionStateChange(callback: (isActivated: boolean) => void)
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ciCalled when the component activation status changes. **onStateChange(true)** is called when the **\<NavRouter>** component is activated and its **\<NavDestination>** child component is loaded. **onStateChange(false)** is called when the **\<NavDestination>** child component is not displayed.
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci**Parameters**
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci| Name     | Type   | Mandatory| Description                                   |
97e41f4b71Sopenharmony_ci| ----------- | ------- | ---- | --------------------------------------- |
98e41f4b71Sopenharmony_ci| isActivated | boolean | Yes  | Component activation status. The value **true** means that component is activated, and **false** means the opposite.|
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci## Example
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci```ts
103e41f4b71Sopenharmony_ci// xxx.ets
104e41f4b71Sopenharmony_ci@Entry
105e41f4b71Sopenharmony_ci@Component
106e41f4b71Sopenharmony_cistruct NavRouterExample {
107e41f4b71Sopenharmony_ci  @State isActiveWLAN: boolean = false
108e41f4b71Sopenharmony_ci  @State isActiveBluetooth: boolean = false
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci  build() {
111e41f4b71Sopenharmony_ci    Navigation() {
112e41f4b71Sopenharmony_ci      NavRouter() {
113e41f4b71Sopenharmony_ci        Row() {
114e41f4b71Sopenharmony_ci          Row()
115e41f4b71Sopenharmony_ci            .width(30)
116e41f4b71Sopenharmony_ci            .height(30)
117e41f4b71Sopenharmony_ci            .borderRadius(30)
118e41f4b71Sopenharmony_ci            .margin({ left: 3, right: 10 })
119e41f4b71Sopenharmony_ci            .backgroundColor(Color.Pink)
120e41f4b71Sopenharmony_ci          Text(`WLAN`)
121e41f4b71Sopenharmony_ci            .fontSize(22)
122e41f4b71Sopenharmony_ci            .fontWeight(500)
123e41f4b71Sopenharmony_ci            .textAlign(TextAlign.Center)
124e41f4b71Sopenharmony_ci        }
125e41f4b71Sopenharmony_ci        .width('90%')
126e41f4b71Sopenharmony_ci        .height(60)
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci        NavDestination() {
129e41f4b71Sopenharmony_ci          Flex({ direction: FlexDirection.Row }) {
130e41f4b71Sopenharmony_ci            Text('No WLAN available.').fontSize(30).padding({ left: 15 })
131e41f4b71Sopenharmony_ci          }
132e41f4b71Sopenharmony_ci        }.title("WLAN")
133e41f4b71Sopenharmony_ci      }
134e41f4b71Sopenharmony_ci      .margin({ top: 10, bottom: 10 })
135e41f4b71Sopenharmony_ci      .backgroundColor(this.isActiveWLAN ? '#ccc' : '#fff')
136e41f4b71Sopenharmony_ci      .borderRadius(20)
137e41f4b71Sopenharmony_ci      .mode(NavRouteMode.PUSH_WITH_RECREATE)
138e41f4b71Sopenharmony_ci      .onStateChange((isActivated: boolean) => {
139e41f4b71Sopenharmony_ci        this.isActiveWLAN = isActivated
140e41f4b71Sopenharmony_ci      })
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci      NavRouter() {
143e41f4b71Sopenharmony_ci        Row() {
144e41f4b71Sopenharmony_ci          Row()
145e41f4b71Sopenharmony_ci            .width(30)
146e41f4b71Sopenharmony_ci            .height(30)
147e41f4b71Sopenharmony_ci            .borderRadius(30)
148e41f4b71Sopenharmony_ci            .margin({ left: 3, right: 10 })
149e41f4b71Sopenharmony_ci            .backgroundColor(Color.Pink)
150e41f4b71Sopenharmony_ci          Text (`Bluetooth`)
151e41f4b71Sopenharmony_ci            .fontSize(22)
152e41f4b71Sopenharmony_ci            .fontWeight(500)
153e41f4b71Sopenharmony_ci            .textAlign(TextAlign.Center)
154e41f4b71Sopenharmony_ci        }
155e41f4b71Sopenharmony_ci        .width('90%')
156e41f4b71Sopenharmony_ci        .height(60)
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_ci        NavDestination() {
159e41f4b71Sopenharmony_ci          Flex({ direction: FlexDirection.Row }) {
160e41f4b71Sopenharmony_ci            Text ('No Bluetooth device available.') .fontSize (30).padding ({ left:15 })
161e41f4b71Sopenharmony_ci          }
162e41f4b71Sopenharmony_ci        }.title("Bluetooth")
163e41f4b71Sopenharmony_ci      }
164e41f4b71Sopenharmony_ci      .margin({ top: 10, bottom: 10 })
165e41f4b71Sopenharmony_ci      .backgroundColor(this.isActiveBluetooth ? '#ccc' : '#fff')
166e41f4b71Sopenharmony_ci      .borderRadius(20)
167e41f4b71Sopenharmony_ci      .mode(NavRouteMode.REPLACE)
168e41f4b71Sopenharmony_ci      .onStateChange((isActivated: boolean) => {
169e41f4b71Sopenharmony_ci        this.isActiveBluetooth = isActivated
170e41f4b71Sopenharmony_ci      })
171e41f4b71Sopenharmony_ci    }
172e41f4b71Sopenharmony_ci    .height('100%')
173e41f4b71Sopenharmony_ci    .width('100%')
174e41f4b71Sopenharmony_ci    .title ('Settings')
175e41f4b71Sopenharmony_ci    .backgroundColor("#F2F3F5")
176e41f4b71Sopenharmony_ci    .titleMode(NavigationTitleMode.Free)
177e41f4b71Sopenharmony_ci    .mode(NavigationMode.Auto)
178e41f4b71Sopenharmony_ci  }
179e41f4b71Sopenharmony_ci}
180e41f4b71Sopenharmony_ci```
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ci![NavRouter](./figures/NavRouter.gif)
183