I'm trying to open specific URL into an ionic app...
The whole setup to open "general" URLs it's done and running so good, but now the thing is about to open specific URLs.
I have this function in app.component.ts:
setupDeepLinks(){
this.deepLinks.route({
'/event-detail/:id':EventDetailPage,
'/search':SearchPage
}).subscribe(match => {
alert(JSON.stringify(match));
},noMatch => {
alert(JSON.stringify(noMatch));
});
}
The entire info about this, says that this is the right way, even the official info from ionic deepLinking...
Opening the DevTools from Chrome I got this error, but I don't know what to do...
I'm working with ionic6
Solution
setupDeepLinks(){
this.deepLinks.route({
'/:id':'/event-detail',
'':'/search'
}).subscribe(match => {
console.log('Success: ', match);
const internalPath = `/${match.$route}/${match.$args['id']}`;
this.zone.run(()=>{
this.router.navigateByUrl(internalPath);
});
},noMatch => {
console.error('Error: ', noMatch);
});
}
Actually it was something really easy, but I didn't found this anywhere.
The routes must be builded like this:
'/:id':'/event-detail',
'':'/search'
When the route expect an ID, the first part of the array it has to looks like this: '/:id' and the second part of the array like this: '/event-detail'
The second part of the array is the name that it's placed on the app-routing.module.ts
When the route doesn't expect anything, the first part of the array it has to be empty and the second part of the array like this: '/search'
I hope this help somebody else.
