当我点击电子邮件中的链接时,如何在应用程序中路由



我想从电子邮件中的链接打开应用程序Android(Nativescript(中的组件,即单击此处重置密码

我在电子邮件中有这样的链接:

http://secsystem.domain.tk/v1/resetPassword/11E8FC9

因此,当我从手机浏览器点击链接时,我需要在组件resetPassword中启动的应用程序。

我使用以下代码:

AndroidManifest.xml

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="secsystem.domain.tk" android:path="/v1/resetPassword"></data> 
</intent-filter>

此代码仅在此url中有效:http://secsystem.domain.tk/v1/resetPassword

我想在此url中工作:http://secsystem.domain.tk/v1/resetPassword/11E8FC9

在routing.ts中,我写了这样的代码:

{ path: 'v1/resetPassword/:id', component: ResetPassIdComponent },

我想在单击链接时打开此组件。

有什么解决办法吗?

当路径具有动态参数时,应该使用android:pathPattern

示例

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="secsystem.domain.tk" android:path="/v1/resetPassword/.*"></data> 
</intent-filter>

到目前为止,这一切都是为了让Android明白,当这个特定的URL模式匹配时,它必须打开这个应用程序。Angular与此无关。如果您想在使用此URL模式打开应用程序时导航到特定组件,则必须手动处理。

安装nativescript-urlhandler插件,在应用程序组件中查询用于打开应用程序的URL,并相应地在路由器中启动导航。

import { Component, OnInit } from "@angular/core";
import { handleOpenURL, AppURL } from 'nativescript-urlhandler';
@Component({
selector: "gr-main",
template: "<page-router-outlet></page-router-outlet>"
})
export class AppComponent {
constructor() {
} 
ngOnInit(){
handleOpenURL((appURL: AppURL) => {
console.log('Got the following appURL', appURL);
});
}
}

最新更新