1e41f4b71Sopenharmony_ci# Starting a Specified Page
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ciWhen the launch type of a PageAbility is set to **singleton** (default), the **onNewWant()** callback is triggered if the PageAbility is not started for the first time. For details about the launch type, see [PageAbility Launch Type](pageability-launch-type.md). In this case, you can use the **want** parameter to transfer startup information. For example, if you want to start a PageAbility with a specified page, pass the pages information in **parameters** of **want**.
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciIn **app.ets** or **page** of the caller PageAbility, use **startAbility()** to start the PageAbility again, with the page information passed in the **uri** parameter in **want**.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci```ts
10e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility';
11e41f4b71Sopenharmony_ciimport Want from '@ohos.app.ability.Want';
12e41f4b71Sopenharmony_ciimport hilog from '@ohos.hilog';
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ciconst TAG: string = 'PagePageAbilityFirst';
15e41f4b71Sopenharmony_ciconst domain: number = 0xFF00;
16e41f4b71Sopenharmony_ci```
17e41f4b71Sopenharmony_ci```ts
18e41f4b71Sopenharmony_ci(async (): Promise<void> => {
19e41f4b71Sopenharmony_ci  let wantInfo: Want = {
20e41f4b71Sopenharmony_ci    bundleName: 'com.samples.famodelabilitydevelop',
21e41f4b71Sopenharmony_ci    abilityName: 'com.samples.famodelabilitydevelop.PageAbilitySingleton',
22e41f4b71Sopenharmony_ci    parameters: { page: 'pages/second' }
23e41f4b71Sopenharmony_ci  };
24e41f4b71Sopenharmony_ci  featureAbility.startAbility({ want: wantInfo }).then((data) => {
25e41f4b71Sopenharmony_ci    hilog.debug(domain, TAG, `restartAbility success : ${data}`);
26e41f4b71Sopenharmony_ci  });
27e41f4b71Sopenharmony_ci})()
28e41f4b71Sopenharmony_ci```
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ciObtain the **want** parameter that contains the page information from the **onNewWant()** callback of the target PageAbility.
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci```ts
34e41f4b71Sopenharmony_ci// Construct a singleton object in GlobalContext.ts.
35e41f4b71Sopenharmony_ciexport class GlobalContext {
36e41f4b71Sopenharmony_ci  private constructor() {
37e41f4b71Sopenharmony_ci  }
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci  private static instance: GlobalContext;
40e41f4b71Sopenharmony_ci  private _objects = new Map<string, Object>();
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci  public static getContext(): GlobalContext {
43e41f4b71Sopenharmony_ci    if (!GlobalContext.instance) {
44e41f4b71Sopenharmony_ci      GlobalContext.instance = new GlobalContext();
45e41f4b71Sopenharmony_ci    }
46e41f4b71Sopenharmony_ci    return GlobalContext.instance;
47e41f4b71Sopenharmony_ci  }
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci  getObject(value: string): Object | undefined {
50e41f4b71Sopenharmony_ci    return this._objects.get(value);
51e41f4b71Sopenharmony_ci  }
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci  setObject(key: string, objectClass: Object): void {
54e41f4b71Sopenharmony_ci    this._objects.set(key, objectClass);
55e41f4b71Sopenharmony_ci  }
56e41f4b71Sopenharmony_ci}
57e41f4b71Sopenharmony_ci```
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci```ts
60e41f4b71Sopenharmony_ciimport Want from '@ohos.app.ability.Want';
61e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility';
62e41f4b71Sopenharmony_ciimport { GlobalContext } from '../utils/GlobalContext';
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ciclass PageAbilitySingleton {
65e41f4b71Sopenharmony_ci  onNewWant(want: Want) {
66e41f4b71Sopenharmony_ci    featureAbility.getWant().then((want) => {
67e41f4b71Sopenharmony_ci      GlobalContext.getContext().setObject('newWant', want);
68e41f4b71Sopenharmony_ci    })
69e41f4b71Sopenharmony_ci  }
70e41f4b71Sopenharmony_ci}
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ciexport default new PageAbilitySingleton();
73e41f4b71Sopenharmony_ci```
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ciObtain the **want** parameter that contains the page information from the custom component of the target PageAbility and process the route based on the URI.
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci```ts
79e41f4b71Sopenharmony_ciimport Want from '@ohos.app.ability.Want';
80e41f4b71Sopenharmony_ciimport router from '@ohos.router';
81e41f4b71Sopenharmony_ciimport { GlobalContext } from '../../utils/GlobalContext';
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci@Entry
84e41f4b71Sopenharmony_ci@Component
85e41f4b71Sopenharmony_cistruct First {
86e41f4b71Sopenharmony_ci  onPageShow() {
87e41f4b71Sopenharmony_ci    let newWant = GlobalContext.getContext().getObject('newWant') as Want;
88e41f4b71Sopenharmony_ci    if (newWant) {
89e41f4b71Sopenharmony_ci      if (newWant.parameters) {
90e41f4b71Sopenharmony_ci        if (newWant.parameters.page) {
91e41f4b71Sopenharmony_ci          router.pushUrl({ url: newWant.parameters.page as string});
92e41f4b71Sopenharmony_ci          GlobalContext.getContext().setObject("newWant", undefined)
93e41f4b71Sopenharmony_ci        }
94e41f4b71Sopenharmony_ci      }
95e41f4b71Sopenharmony_ci    }
96e41f4b71Sopenharmony_ci  }
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci  build() {
99e41f4b71Sopenharmony_ci    Column() {
100e41f4b71Sopenharmony_ci      Row() {
101e41f4b71Sopenharmony_ci        Text('singleton_first_title')
102e41f4b71Sopenharmony_ci          .fontSize(24)
103e41f4b71Sopenharmony_ci          .fontWeight(FontWeight.Bold)
104e41f4b71Sopenharmony_ci          .textAlign(TextAlign.Start)
105e41f4b71Sopenharmony_ci          .margin({ top: 12, bottom: 11, right: 24, left: 24 })
106e41f4b71Sopenharmony_ci      }
107e41f4b71Sopenharmony_ci      .width('100%')
108e41f4b71Sopenharmony_ci      .height(56)
109e41f4b71Sopenharmony_ci      .justifyContent(FlexAlign.Start)
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci      Image('pic_empty')
112e41f4b71Sopenharmony_ci        .width(120)
113e41f4b71Sopenharmony_ci        .height(120)
114e41f4b71Sopenharmony_ci        .margin({ top: 224 })
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci      Text('no_content')
117e41f4b71Sopenharmony_ci        .fontSize(14)
118e41f4b71Sopenharmony_ci        .margin({ top: 8, bottom: 317, right: 152, left: 152 })
119e41f4b71Sopenharmony_ci        .fontColor('text_color')
120e41f4b71Sopenharmony_ci        .opacity(0.4)
121e41f4b71Sopenharmony_ci    }
122e41f4b71Sopenharmony_ci    .width('100%')
123e41f4b71Sopenharmony_ci    .height('100%')
124e41f4b71Sopenharmony_ci    .backgroundColor('backGrounding')
125e41f4b71Sopenharmony_ci  }
126e41f4b71Sopenharmony_ci}
127e41f4b71Sopenharmony_ci```
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ciWhen a PageAbility in multiton mode is started or when the PageAbility in singleton mode is started for the first time, you can use the **parameters** parameter in **want** to transfer the pages information and use the **startAbility()** method to start the PageAbility. For details about the launch type, see [PageAbility Launch Type](pageability-launch-type.md). The target PageAbility can use the **featureAbility.getWant()** method in **onCreate** to obtain the **want** parameter, and then call **router.pushUrl** to start a specified page.
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ciWhen a user touches the button on the page of the caller PageAbility, the **startAbility()** method is called to start the target PageAbility. The **want** parameter in **startAbility()** carries the specified page information.
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci```ts
136e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility';
137e41f4b71Sopenharmony_ciimport Want from '@ohos.app.ability.Want';
138e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
139e41f4b71Sopenharmony_ciimport fs from '@ohos.file.fs';
140e41f4b71Sopenharmony_ciimport promptAction from '@ohos.promptAction';
141e41f4b71Sopenharmony_ciimport worker from '@ohos.worker';
142e41f4b71Sopenharmony_ciimport hilog from '@ohos.hilog';
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ciconst TAG: string = 'PagePageAbilityFirst';
145e41f4b71Sopenharmony_ciconst domain: number = 0xFF00;
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_ci@Entry
148e41f4b71Sopenharmony_ci@Component
149e41f4b71Sopenharmony_cistruct PagePageAbilityFirst {
150e41f4b71Sopenharmony_ci  build() {
151e41f4b71Sopenharmony_ci    Column() {
152e41f4b71Sopenharmony_ci      //...
153e41f4b71Sopenharmony_ci      List({ initialIndex: 0 }) {
154e41f4b71Sopenharmony_ci        //...
155e41f4b71Sopenharmony_ci        ListItem() {
156e41f4b71Sopenharmony_ci          Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
157e41f4b71Sopenharmony_ci          //...
158e41f4b71Sopenharmony_ci          }
159e41f4b71Sopenharmony_ci          .onClick(() => {
160e41f4b71Sopenharmony_ci            let want: Want = {
161e41f4b71Sopenharmony_ci              bundleName: 'com.samples.famodelabilitydevelop',
162e41f4b71Sopenharmony_ci              abilityName: 'com.samples.famodelabilitydevelop.PageAbilityStandard',
163e41f4b71Sopenharmony_ci              parameters: { page: 'pages/first' }
164e41f4b71Sopenharmony_ci            };
165e41f4b71Sopenharmony_ci            featureAbility.startAbility({ want: want }).then((data) => {
166e41f4b71Sopenharmony_ci              hilog.info(domain, TAG, `startAbility finish:${data}`);
167e41f4b71Sopenharmony_ci            }).catch((err: BusinessError) => {
168e41f4b71Sopenharmony_ci              hilog.info(domain, TAG, `startAbility failed errcode:${err.code}`);
169e41f4b71Sopenharmony_ci            })
170e41f4b71Sopenharmony_ci          })
171e41f4b71Sopenharmony_ci        }
172e41f4b71Sopenharmony_ci        //...
173e41f4b71Sopenharmony_ci        ListItem() {
174e41f4b71Sopenharmony_ci          Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
175e41f4b71Sopenharmony_ci          //...
176e41f4b71Sopenharmony_ci          }
177e41f4b71Sopenharmony_ci          .onClick(() => {
178e41f4b71Sopenharmony_ci            let want: Want = {
179e41f4b71Sopenharmony_ci              bundleName: 'com.samples.famodelabilitydevelop',
180e41f4b71Sopenharmony_ci              abilityName: 'com.samples.famodelabilitydevelop.PageAbilityStandard',
181e41f4b71Sopenharmony_ci              parameters: { page: 'pages/second' }
182e41f4b71Sopenharmony_ci            };
183e41f4b71Sopenharmony_ci            featureAbility.startAbility({ want: want }).then((data) => {
184e41f4b71Sopenharmony_ci              hilog.info(domain, TAG, `startAbility finish:${data}`);
185e41f4b71Sopenharmony_ci            }).catch((err: BusinessError) => {
186e41f4b71Sopenharmony_ci              hilog.info(domain, TAG, `startAbility failed errcode:${err.code}`);
187e41f4b71Sopenharmony_ci            })
188e41f4b71Sopenharmony_ci          })
189e41f4b71Sopenharmony_ci        }
190e41f4b71Sopenharmony_ci        //...
191e41f4b71Sopenharmony_ci      }
192e41f4b71Sopenharmony_ci      //...
193e41f4b71Sopenharmony_ci    }
194e41f4b71Sopenharmony_ci    //...
195e41f4b71Sopenharmony_ci  }
196e41f4b71Sopenharmony_ci}
197e41f4b71Sopenharmony_ci```
198e41f4b71Sopenharmony_ci
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ciIn the **onCreate()** callback of the target PageAbility, use the **featureAbility.getWant()** method to obtain the **want** parameter, parse the parameter, and start the specified page.
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_ci```ts
203e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility';
204e41f4b71Sopenharmony_ciimport router from '@ohos.router';
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_ciclass PageAbilityStandard {
207e41f4b71Sopenharmony_ci  onCreate() {
208e41f4b71Sopenharmony_ci    featureAbility.getWant().then((want) => {
209e41f4b71Sopenharmony_ci      if (want.parameters) {
210e41f4b71Sopenharmony_ci        if (want.parameters.page) {
211e41f4b71Sopenharmony_ci          router.pushUrl({ url: want.parameters.page as string });
212e41f4b71Sopenharmony_ci        }
213e41f4b71Sopenharmony_ci      }
214e41f4b71Sopenharmony_ci    })
215e41f4b71Sopenharmony_ci  }
216e41f4b71Sopenharmony_ci}
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ciexport default new PageAbilityStandard();
219e41f4b71Sopenharmony_ci```
220