我在实现DeepLinks时遇到了问题。我可以从URL打开应用程序,比如myapp://myapp.com/ open。但它不能处理它的路径。它只会打开程序。
我打开它时:
this.deeplinks.route({
'/route': RoutePage
}).subscribe(match => {
// match.$route - the route we matched, which is the matched entry from the arguments to route()
// match.$args - the args passed in the link
// match.$link - the full link data
console.log('Successfully matched route', match);
}, nomatch => {
// nomatch.$link - the full link data
console.error('Got a deeplink that didn\'t match', nomatch);
});
但是,我没有收到任何控制台日志,路径是空的,只需要以下消息:
我的config.xml
<plugin name="ionic-plugin-deeplinks" spec="^1.0.17">
<variable name="URL_SCHEME" value="iskibris" />
<variable name="DEEPLINK_SCHEME" value="https" />
<variable name="DEEPLINK_HOST" value="iskibris.com" />
<variable name="ANDROID_PATH_PREFIX" value="/" />
<variable name="ANDROID_2_PATH_PREFIX" value="/" />
<variable name="ANDROID_3_PATH_PREFIX" value="/" />
<variable name="ANDROID_4_PATH_PREFIX" value="/" />
<variable name="ANDROID_5_PATH_PREFIX" value="/" />
<variable name="DEEPLINK_2_SCHEME" value="" />
<variable name="DEEPLINK_2_HOST" value="" />
<variable name="DEEPLINK_3_SCHEME" value="" />
<variable name="DEEPLINK_3_HOST" value="" />
<variable name="DEEPLINK_4_SCHEME" value="" />
<variable name="DEEPLINK_4_HOST" value="" />
<variable name="DEEPLINK_5_SCHEME" value="" />
<variable name="DEEPLINK_5_HOST" value="" />
</plugin>
打电话给这个应用的链接://iskibris.com/ help,有人能帮我吗?
发布于 2018-08-16 15:37:20
Ionic Deeplinks
有两个方法来打开另一个页面。
当使用route
方法时,您应该使用nav.push导航另一个页面。您可以在app.component.ts
中实现它,如下所示。
@ViewChild(Nav) nav:Nav;
constructor(private deeplinks: Deeplinks) {
platform.ready().then(() => {
this.deeplinks.route({
'/about': AboutPage
}).subscribe(match => {
this.nav.push(AboutPage);
}, nomatch => {
console.error('Got a deeplink that didn\'t match', nomatch);
});
});
}
}
或者使用routeWithNavController
对NavController
进行引用并处理实际导航。routeWithNavController
方法可以在app.component.ts
中实现如下所示
@ViewChild(Nav) nav:Nav;
constructor(private deeplinks: Deeplinks) {
platform.ready().then(() => {
this.deeplinks.routeWithNavController(this.nav, {
'/about': AboutPage
}).subscribe(match => {
console.log('Successfully matched route', JSON.stringify(match, null, 2));
}, nomatch => {
console.error('Got a deeplink that didn\'t match', nomatch);
});
});
}
还有一点,在您的config.xml中,<variable name="URL_SCHEME" value="iskibris" />
应该更改为<variable name="URL_SCHEME" value="myapp" />
。
发布于 2021-08-03 01:28:06
对我来说,唯一可行的方法是,奇怪的是,使用routeWithNavController方法并在第二个参数上传递一个空对象。顺便说一下,我正在Ionic 3上测试iPhone仿真器。
以下是测试结果:
/**
* Using the routeWithNavController method and passing an empty object on the second parameter
* WORKS!!
* Did open the app and fired the "match" callback with the info of the clicked link
*/
this.platform.ready().then(() => {
this.deeplinks.routeWithNavController(this.nav, {
// Nothing here. Empty object
}).subscribe((match) => {
alert('Match');
alert(JSON.stringify(match));
}, (nomatch) => {
alert('No Match');
alert(JSON.stringify(nomatch));
});
});
下面的示例没有使用。
/**
* Using the routeWithNavController method and passing an object with a "what would be" route on the second parameter
* DOESN`T WORK
* Did open the app but didn't fire any of the callbacks. Neither "match" or "nomatch"
*/
this.platform.ready().then(() => {
this.deeplinks.routeWithNavController(this.nav, {
'/': {}
}).subscribe((match) => {
alert('Match');
alert(JSON.stringify(match));
}, (nomatch) => {
alert('No Match');
alert(JSON.stringify(nomatch));
});
});
/**
* Using the route method and passing an object empty object
* DOESN'T WORK (kinda)
* Did open the app and fired the nomatch callback (after all, no route specified)
*/
this.platform.ready().then(() => {
this.deeplinks.route({
// Nothing here. Empty object,
}).subscribe((match) => {
alert('Match');
alert(JSON.stringify(match));
},
(nomatch) => {
alert('No Match');
alert(JSON.stringify(nomatch));
});
});
/**
* Using the route method and passing object with a "what would be" route on the second parameter
* By the way, here I tried both links:
* myapp://myapp.domain.com/
* myapp://myapp.domain.com
* DOESN`T WORK
* Did open the app but didn't fire any of the callbacks. Neither "match" or "nomatch"
*/
this.platform.ready().then(() => {
this.deeplinks.route({
'/': {},
}).subscribe((match) => {
alert('Match');
alert(JSON.stringify(match));
},
(nomatch) => {
alert('No Match');
alert(JSON.stringify(nomatch));
});
});
因为只有第一个工作正常,所以我不得不处理match对象数据并自己执行路由,如下所示:
this.deeplinks.routeWithNavController(this.nav, {}).subscribe((match) => {
if (match.$link.path == "/list") {
this.nav.setRoot(ListPage);
}
}, (nomatch) => {});
下面是我的deeplinks工作app.component.ts的完整代码:
import { Component, ViewChild } from '@angular/core';
import { Nav, Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { HomePage } from '../pages/home/home';
import { ListPage } from '../pages/list/list';
import { Deeplinks } from '@ionic-native/deeplinks';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
rootPage: any = HomePage;
pages: Array<{title: string, component: any}>;
constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, public deeplinks: Deeplinks) {
this.initializeApp();
// used for an example of ngFor and navigation
this.pages = [
{ title: 'Home', component: HomePage },
{ title: 'List', component: ListPage }
];
}
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.statusBar.styleDefault();
this.splashScreen.hide();
this.deeplinks.routeWithNavController(this.nav, {}).subscribe((match) => {
if (match.$link.path == "/list") {
this.nav.setRoot(ListPage);
}
}, (nomatch) => {});
});
}
openPage(page) {
// Reset the content nav to have just this page
// we wouldn't want the back button to show in this scenario
this.nav.setRoot(page.component);
}
}
https://stackoverflow.com/questions/51878423
复制相似问题