How to routing in a app when I click a link from email

杀马特。学长 韩版系。学妹 提交于 2019-12-11 15:50:02

问题


I want to open my component in Application Android (Nativescript) from a link in email, that is Click here to reset password

I have a link like this in email:

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

So when I click the link from my mobile browser I need the app Launched in component resetPassword.

I use the following code:

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>

This code works good only in this url: http://secsystem.domain.tk/v1/resetPassword

I want to work in this url: http://secsystem.domain.tk/v1/resetPassword/11E8FC9

In routing.ts I write this code:

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

I want to open this component when I click in link.

Is there any solution for this?


回答1:


You should use android:pathPattern when the path has dynamic parameter.

Example

<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>

So far this is all about making Android understand it has to open this app when this particular URL pattern is matched. Angular has nothing to do here. If you want to navigate to particular component when app is opened with this URL pattern, then you must handle it manually.

Install nativescript-urlhandler plugin and query the URL that was used to open the app in the app component and initiate navigation in your router accordingly.

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);
        });
     }
}


来源:https://stackoverflow.com/questions/53746560/how-to-routing-in-a-app-when-i-click-a-link-from-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!