【问题标题】:How to routing in a app when I click a link from email当我单击电子邮件中的链接时如何在应用程序中路由
【发布时间】:2018-12-12 15:43:21
【问题描述】:

我想通过电子邮件中的链接在 Application 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

我想在这个网址工作:http://secsystem.domain.tk/v1/resetPassword/11E8FC9

在 routing.ts 我写了这段代码:

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

我想在点击链接时打开这个组件。

有什么解决办法吗?

【问题讨论】:

  • 如果你想通过额外的参数保持路径动态,请使用android:pathPattern
  • 你能写代码吗?
  • 应该是android:pathPattern="/v1/resetPassword/.*"
  • 我像你说的那样尝试,效果很好。但不会在这条路径上溃败v1/resetPassword/:id,组件ResetPassIdComponent 请问您有什么想法吗?

标签: android angular typescript nativescript


【解决方案1】:

当路径有动态参数时,你应该使用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);
        });
     }
}

【讨论】:

  • 在控制台显示Got the following appURL http://secsystem.domain.tk/v1/resetPassword/11E8FC9。现在,如何打开这个组件ResetPassIdComponent ??谢谢
  • 解析你想要发送到路由器的部分 URL 并使用 navigatByUrl 启动导航。
  • 在组件 app.component.ts 我写 handleOpenURL((appURL: AppURL) =&gt; {this.router.navigate(['/resetPassword']);}); 在 routing.ts { path: '/resetPassword', component: ResetPassIdComponent }, 现在问题是,首先在应用程序中打开第一个组件,几秒钟打开这个组件。这个ResetPassIdComponent怎么直接打开??
  • @Manoj 它是否适用于查询参数?因为我遇到了这个问题:stackoverflow.com/questions/56970072/…
猜你喜欢
  • 1970-01-01
  • 2012-01-14
  • 2021-11-01
  • 2014-09-13
  • 2021-12-29
  • 2015-09-03
  • 2011-10-21
  • 1970-01-01
  • 2012-08-31
相关资源
最近更新 更多