1e41f4b71Sopenharmony_ci# Using Deep Linking for Application Redirection 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciIn Deep Linking, the system, based on the passed-in URI and [URI matching rules](explicit-implicit-want-mappings.md#matching-rules-of-uri), searches for the application that meets the URL skills configuration from the locally installed applications and starts that application. If multiple applications are matched, a dialog box is displayed for users to select one of them. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci## Working Principles 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciDeep Linking searches for an application based on the URI matching rules in implicit Want mechanism and starts the matching application. For details about the URI matching rules of implicit Want, see [Matching Rules of uri](explicit-implicit-want-mappings.md#matching-rules-of-uri). 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Declaring the URL Skills in the Configuration File (Required for the Target Application) 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ciTo be accessed by other applications, an application must declare the URL skills in the [module.json5 file](../quick-start/module-configuration-file.md). The value of **scheme** under **uri** can be customized. It can be any string that does not contain special characters or start with **ohos**. 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ciA configuration example is as follows: 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci```json 17e41f4b71Sopenharmony_ci{ 18e41f4b71Sopenharmony_ci "module": { 19e41f4b71Sopenharmony_ci // ... 20e41f4b71Sopenharmony_ci "abilities": [ 21e41f4b71Sopenharmony_ci { 22e41f4b71Sopenharmony_ci // ... 23e41f4b71Sopenharmony_ci "skills": [ 24e41f4b71Sopenharmony_ci { 25e41f4b71Sopenharmony_ci "uris": [ 26e41f4b71Sopenharmony_ci { 27e41f4b71Sopenharmony_ci // scheme is mandatory and can be customized. The following uses link as an example. Replace it with the actual scheme. 28e41f4b71Sopenharmony_ci "scheme": "link", 29e41f4b71Sopenharmony_ci // host is mandatory. Configure the domain name to be matched. 30e41f4b71Sopenharmony_ci "host": "www.example.com", 31e41f4b71Sopenharmony_ci // path is optional. To distinguish between applications that are associated with the same domain name, you are advised to configure this field. 32e41f4b71Sopenharmony_ci "path": "path1" 33e41f4b71Sopenharmony_ci } 34e41f4b71Sopenharmony_ci ] 35e41f4b71Sopenharmony_ci } 36e41f4b71Sopenharmony_ci ] 37e41f4b71Sopenharmony_ci } 38e41f4b71Sopenharmony_ci ] 39e41f4b71Sopenharmony_ci } 40e41f4b71Sopenharmony_ci} 41e41f4b71Sopenharmony_ci``` 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci## Implementing Application Redirection (Required for the Caller Application) 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ciThe following uses two cases to describe how to use [openLink()](../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextopenlink12) and [startAbility()](../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability) to implement application redirection. 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci### Using openLink() to Open a Browser Page 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ciPass in the URL of the target application into **link** of [openLink()](../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextopenlink12), and set **appLinkingOnly** in the **options** field to **false**. 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ciThe sample code is as follows: 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci```ts 56e41f4b71Sopenharmony_ciimport { common } from '@kit.AbilityKit'; 57e41f4b71Sopenharmony_ciimport OpenLinkOptions from '@ohos.app.ability.OpenLinkOptions'; 58e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 59e41f4b71Sopenharmony_ciimport hilog from '@ohos.hilog'; 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ciconst TAG: string = '[UIAbilityComponentsOpenLink]'; 62e41f4b71Sopenharmony_ciconst DOMAIN_NUMBER: number = 0xFF00; 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci@Entry 65e41f4b71Sopenharmony_ci@Component 66e41f4b71Sopenharmony_cistruct Index { 67e41f4b71Sopenharmony_ci build() { 68e41f4b71Sopenharmony_ci Button('start link', { type: ButtonType.Capsule, stateEffect: true }) 69e41f4b71Sopenharmony_ci .width('87%') 70e41f4b71Sopenharmony_ci .height('5%') 71e41f4b71Sopenharmony_ci .margin({ bottom: '12vp' }) 72e41f4b71Sopenharmony_ci .onClick(() => { 73e41f4b71Sopenharmony_ci let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; 74e41f4b71Sopenharmony_ci let link: string = "link://www.example.com"; 75e41f4b71Sopenharmony_ci let openLinkOptions: OpenLinkOptions = { 76e41f4b71Sopenharmony_ci appLinkingOnly: false 77e41f4b71Sopenharmony_ci }; 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci try { 80e41f4b71Sopenharmony_ci context.openLink(link, openLinkOptions) 81e41f4b71Sopenharmony_ci .then(() => { 82e41f4b71Sopenharmony_ci hilog.info(DOMAIN_NUMBER, TAG, 'open link success.'); 83e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 84e41f4b71Sopenharmony_ci hilog.error(DOMAIN_NUMBER, TAG, `open link failed. Code is ${err.code}, message is ${err.message}`); 85e41f4b71Sopenharmony_ci }) 86e41f4b71Sopenharmony_ci } catch (paramError) { 87e41f4b71Sopenharmony_ci hilog.error(DOMAIN_NUMBER, TAG, `Failed to start link. Code is ${paramError.code}, message is ${paramError.message}`); 88e41f4b71Sopenharmony_ci } 89e41f4b71Sopenharmony_ci }) 90e41f4b71Sopenharmony_ci } 91e41f4b71Sopenharmony_ci} 92e41f4b71Sopenharmony_ci``` 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci### Using startAbility() to Implement Application Redirection 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ciPass in the target application's link into **want** of [startAbility](../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability), which then uses [implicit Want](explicit-implicit-want-mappings.md#matching-rules-of-implicit-want) to trigger application redirection. In addition, you must pass in the **action** and **entity** fields to be matched. 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ciThe sample code is as follows: 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci```ts 102e41f4b71Sopenharmony_ciimport { common, Want } from '@kit.AbilityKit'; 103e41f4b71Sopenharmony_ciimport OpenLinkOptions from '@ohos.app.ability.OpenLinkOptions'; 104e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 105e41f4b71Sopenharmony_ciimport hilog from '@ohos.hilog'; 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ciconst TAG: string = '[UIAbilityComponentsOpenLink]'; 108e41f4b71Sopenharmony_ciconst DOMAIN_NUMBER: number = 0xFF00; 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci@Entry 111e41f4b71Sopenharmony_ci@Component 112e41f4b71Sopenharmony_cistruct Index { 113e41f4b71Sopenharmony_ci build() { 114e41f4b71Sopenharmony_ci Button('start ability', { type: ButtonType.Capsule, stateEffect: true }) 115e41f4b71Sopenharmony_ci .width('87%') 116e41f4b71Sopenharmony_ci .height('5%') 117e41f4b71Sopenharmony_ci .margin({ bottom: '12vp' }) 118e41f4b71Sopenharmony_ci .onClick(() => { 119e41f4b71Sopenharmony_ci let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; 120e41f4b71Sopenharmony_ci let want: Want = { 121e41f4b71Sopenharmony_ci uri: "link://www.example.com" 122e41f4b71Sopenharmony_ci }; 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci try { 125e41f4b71Sopenharmony_ci context.startAbility(want).then(() => { 126e41f4b71Sopenharmony_ci hilog.info(DOMAIN_NUMBER, TAG, 'start ability success.'); 127e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 128e41f4b71Sopenharmony_ci hilog.error(DOMAIN_NUMBER, TAG, `start ability failed. Code is ${err.code}, message is ${err.message}`); 129e41f4b71Sopenharmony_ci }) 130e41f4b71Sopenharmony_ci } catch (paramError) { 131e41f4b71Sopenharmony_ci hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability. Code is ${paramError.code}, message is ${paramError.message}`); 132e41f4b71Sopenharmony_ci } 133e41f4b71Sopenharmony_ci }) 134e41f4b71Sopenharmony_ci } 135e41f4b71Sopenharmony_ci} 136e41f4b71Sopenharmony_ci``` 137