Ionic 4 Deeplink 插件 return 假路由不匹配
Ionic 4 Deeplink plugin return false route not matched
我正在 ionic 4 应用程序中实施 Deeplink。应用程序正在启动,但 deeplink 插件总是 returns false
;
app.routing.ts:
{
path: 'viewdiary/:id/public',
loadChildren: () => import('./pages/viewdiary/viewdiary.module').then( m => m.ViewdiaryPageModule)
},
app.compoent.ts:
setupDeepLink(){
this.deeplinks.route({
'/viewdiary/:id/public': 'viewdiary/:id/public'
}).subscribe((match)=>{
console.log('deeplink matched', match);
const internalPath = `${match.$route}/${match.$args['id']}/${match.$route}`;
console.log(internalPath);
this.zone.run(()=>{
this.general.goToPage(internalPath);
});
},
nomatch=>{
// nomatch.$link - the full link data
console.error("Got a deeplink that didn't match", nomatch);
})
};
我的 Public 日记页面 link 是 'https://www.example.com/diary/12542/public';
看起来路由问题尝试了很多东西更改名称但没有任何效果。我不知道哪里出了问题。
对我来说,这种方法也行不通。因此,在我的应用程序中,我按如下方式处理深层链接:
const {App}: { App: AppPlugin } = Plugins;
...
export class AppComponent {
private setupDeepLinks(): void {
App.addListener('appUrlOpen', (data: any) => {
this.ngZone.run(() => {
// Example url: https://my-domain.com/tabs/tab2
// slug = /tabs/tab2
const slug = data.url.split('my-domain.com').pop();
if (slug) {
this.router.navigateByUrl(slug);
}
});
});
}
}
或者,如果需要,您可以在侦听器中实现自己更复杂的逻辑
在 WhosebugAnother Answer 的帮助下弄清楚如何实现它
import { Platform, NavController } from '@ionic/angular';
constructor(public navCtrl: NavController){}
this.deeplinks.routeWithNavController(this.nav, {
'/viewdiary/:diary/:id/:public': 'viewdiary'
}).subscribe((match) => {
console.log('success' + JSON.stringify(match));
}, (noMatch) => {
console.log('error' + JSON.stringify(noMatch));
});
我正在 ionic 4 应用程序中实施 Deeplink。应用程序正在启动,但 deeplink 插件总是 returns false
;
app.routing.ts:
{
path: 'viewdiary/:id/public',
loadChildren: () => import('./pages/viewdiary/viewdiary.module').then( m => m.ViewdiaryPageModule)
},
app.compoent.ts:
setupDeepLink(){
this.deeplinks.route({
'/viewdiary/:id/public': 'viewdiary/:id/public'
}).subscribe((match)=>{
console.log('deeplink matched', match);
const internalPath = `${match.$route}/${match.$args['id']}/${match.$route}`;
console.log(internalPath);
this.zone.run(()=>{
this.general.goToPage(internalPath);
});
},
nomatch=>{
// nomatch.$link - the full link data
console.error("Got a deeplink that didn't match", nomatch);
})
};
我的 Public 日记页面 link 是 'https://www.example.com/diary/12542/public';
看起来路由问题尝试了很多东西更改名称但没有任何效果。我不知道哪里出了问题。
对我来说,这种方法也行不通。因此,在我的应用程序中,我按如下方式处理深层链接:
const {App}: { App: AppPlugin } = Plugins;
...
export class AppComponent {
private setupDeepLinks(): void {
App.addListener('appUrlOpen', (data: any) => {
this.ngZone.run(() => {
// Example url: https://my-domain.com/tabs/tab2
// slug = /tabs/tab2
const slug = data.url.split('my-domain.com').pop();
if (slug) {
this.router.navigateByUrl(slug);
}
});
});
}
}
或者,如果需要,您可以在侦听器中实现自己更复杂的逻辑
在 WhosebugAnother Answer 的帮助下弄清楚如何实现它
import { Platform, NavController } from '@ionic/angular';
constructor(public navCtrl: NavController){}
this.deeplinks.routeWithNavController(this.nav, {
'/viewdiary/:diary/:id/:public': 'viewdiary'
}).subscribe((match) => {
console.log('success' + JSON.stringify(match));
}, (noMatch) => {
console.log('error' + JSON.stringify(noMatch));
});