from my typescript code and add additional data like ionic3:
this.navCtrl.push(AboutPage, {
data: color
});
i think i should use @angular/router , but as i understand router.navigateByUrl can’t add data (is this right??) and i somehow can’t get router.navigate(['/tabs/(profile:profile)', {data: data}]); to work, it says “Error: Cannot match any routes. URL Segment: ‘tabs’”
for any1 who is interested in this, apparently it should work like this
0.1 Import (for beginners)
import { ActivatedRoute } from '@angular/router'
import { Router } from '@angular/router';
constructor(
private route: ActivatedRoute,
public router: Router
) {
}
Navigate
// Set our navigation extras object
// that contains our global query params and fragment
let navigationExtras: NavigationExtras = {
queryParams: { 'session_id': sessionId },
fragment: 'anchor'
};
// Navigate to the login page with extras
this.router.navigate(['/login'], navigationExtras);
Url
/login?session_id=123456789#anchor
Recieve
ngOnInit() {
// Capture the session ID if available
this.sessionId = this.route
.queryParamMap
.pipe(map(params => params.get('session_id') || 'None'));
// Capture the fragment if available
this.token = this.route
.fragment
.pipe(map(fragment => fragment || 'None'));
}
you also can pas Data, but i would recommend you to try to use only URL Data, it makes it really easy to release your ionic 4 app For Browser with links that you can copy and share